[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Bug#28713 acknowledged by developer (Non-embedded viewers always launch "save-open-cancel" dialo
From:       Waldo Bastian <bastian () kde ! org>
Date:       2001-07-12 23:36:46
[Download RAW message or body]

On Thursday 12 July 2001 01:56 am, David Faure wrote:
> On Thursday 12 July 2001 11:43, Anders Gorm Pedersen wrote:
> > Would it perhaps be possible to do something along the lines of the
> > Windows (gasp!) solution where sometimes a dialog will have a small tick
> > box saying "do not show this warning again"?
>
> KDE has such boxes too :)
> Hmm, this would be easy if warningYesNoCancel supported such checkboxes,
> but only continueCancel currently does :(
>
> Waldo, would it be ok to add a dontShowAgainName to warningYesNoCancel ?
> In that case, we would have to actually store whether yes or no was
> selected...

Please review the following patch.

Cheers,
Waldo
-- 
I don't suffer from insanity,
          I enjoy every minute of it.

["kmessagebox.diff" (text/x-diff)]

Index: kmessagebox.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kmessagebox.cpp,v
retrieving revision 1.31
diff -u -3 -d -p -r1.31 kmessagebox.cpp
--- kmessagebox.cpp	2001/05/25 23:29:57	1.31
+++ kmessagebox.cpp	2001/07/12 23:41:25
@@ -273,8 +273,37 @@ int
 KMessageBox::warningYesNoCancel(QWidget *parent, const QString &text,
                                 const QString &caption,
                                 const QString &buttonYes,
-                                const QString &buttonNo, bool /*notify*/)
+                                const QString &buttonNo, bool notify)
+{
+   return warningYesNoCancel(parent, text, caption, buttonYes, buttonNo,
+	QString::null, notify);
+}
+
+int
+KMessageBox::warningYesNoCancel(QWidget *parent, const QString &text,
+                                const QString &caption,
+                                const QString &buttonYes,
+                                const QString &buttonNo, 
+                                const QString &dontAskAgainName,
+                                bool /*notify*/)
 {
+    KConfig *config = 0;
+    QString grpNotifMsgs = QString::fromLatin1("Notification Messages");
+
+    if (!dontAskAgainName.isEmpty())
+    {
+       config = kapp->config();
+       KConfigGroupSaver saver( config, grpNotifMsgs );
+       QString dontAsk = config->readEntry( dontAskAgainName).lower();
+       if (dontAsk == "yes")
+       {
+          return Yes;
+       }
+       if (dontAsk == "no")
+       {
+          return No;
+       }
+    }
     KDialogBase *dialog= new KDialogBase(
                        caption.isEmpty() ? i18n("Warning") : caption,
                        KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel,
@@ -282,14 +311,35 @@ KMessageBox::warningYesNoCancel(QWidget 
                        parent, "warningYesNoCancel", true, true,
                        buttonYes, buttonNo);
 
-    int result = createKMessageBox(dialog, QMessageBox::Warning, text, QStringList(), QString::null, 0);
+    bool checkboxResult;
+    int result = createKMessageBox(dialog, QMessageBox::Warning, text, QStringList(), 
+                       dontAskAgainName.isEmpty() ? QString::null : i18n("Do not ask again"),
+                       &checkboxResult);
 
     switch( result )
     {
       case KDialogBase::Yes:
+         if (!dontAskAgainName.isEmpty())
+         {
+            if (checkboxResult)
+            {
+               KConfigGroupSaver saver( config, grpNotifMsgs );
+               config->writeEntry( dontAskAgainName, "Yes");
+            }
+            config->sync();
+         }
          return Yes;
 
       case KDialogBase::No:
+         if (!dontAskAgainName.isEmpty())
+         {
+            if (checkboxResult)
+            {
+               KConfigGroupSaver saver( config, grpNotifMsgs );
+               config->writeEntry( dontAskAgainName, "No");
+            }
+            config->sync();
+         }
          return No;
 
       case KDialogBase::Cancel:
Index: kmessagebox.h
===================================================================
RCS file: /home/kde/kdelibs/kdeui/kmessagebox.h,v
retrieving revision 1.21
diff -u -3 -d -p -r1.21 kmessagebox.h
--- kmessagebox.h	2001/04/29 01:57:51	1.21
+++ kmessagebox.h	2001/07/12 23:41:25
@@ -223,6 +223,12 @@ public:
   *                  The default is i18n("&Yes").
   * @param buttonNo  The text for the second button. 
   *                  The default is i18n("&No").
+  * @param dontAskAgainName If provided, a checkbox is added with which
+  *                further questions can be turned off. If turned off
+  *                all questions will be automatically answered with the
+  *                last answer (either Yes or No). 
+  *                The string is used to lookup and store the setting
+  *                in the applications config file.
   * @param notify  Emit a KNotify event.
   *
   * @return  @p Yes is returned if the Yes-button is pressed. @p No is returned
@@ -242,6 +248,14 @@ public:
                                 const QString &caption = QString::null,
                                 const QString &buttonYes = QString::null,  
                                 const QString &buttonNo = QString::null, bool notify=true);
+
+  static int warningYesNoCancel(QWidget *parent,
+                                const QString &text,
+                                const QString &caption,
+                                const QString &buttonYes,  
+                                const QString &buttonNo, 
+                                const QString &dontAskAgainName,
+                                bool notify=true);
 
  /**
   * Display an "Error" dialog. 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic