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

List:       kde-devel
Subject:    PATCH for KMessageBox (untested)
From:       Holger Freyther <freyther () gmx ! net>
Date:       2001-10-30 23:35:42
[Download RAW message or body]

Hi all,
this patch adds questionYesNoCancel to KMessageBox. Waldo said I could go 
ahead and I did so. 
just call it like the normal way but make sure you add one more argument,
I couldn't test this patch because I'm recompiling everything but it compiled 
and it should work. But I need to go
good night 
Holger


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

diff -urN kde_ui.orig/AUTHORS kdeui/AUTHORS
--- kde_ui.orig/AUTHORS	Wed May 24 23:56:33 2000
+++ kdeui/AUTHORS	Wed Oct 31 00:28:05 2001
@@ -91,3 +91,6 @@
 
 Falk Brettschneider <gigafalk@yahoo.com>
 contributes for the Dockwidget class set
+
+Holger Freyther <freyther@yahoo.com>
+added questionYesNoCancel to KMessageBox
diff -urN kde_ui.orig/kmessagebox.cpp kdeui/kmessagebox.cpp
--- kde_ui.orig/kmessagebox.cpp	Wed Oct 10 19:40:39 2001
+++ kdeui/kmessagebox.cpp	Wed Oct 31 00:16:29 2001
@@ -120,7 +120,7 @@
 KMessageBox::questionYesNo(QWidget *parent, const QString &text,
                            const QString &caption,
                            const QString &buttonYes,
-                           const QString &buttonNo, 
+                           const QString &buttonNo,
                            const QString &dontAskAgainName,
                            bool notify)
 {
@@ -134,7 +134,7 @@
                            const QStringList &strlist,
                            const QString &caption,
                            const QString &buttonYes,
-                           const QString &buttonNo, 
+                           const QString &buttonNo,
                            const QString &dontAskAgainName,
                            bool /*notify*/)
 {
@@ -163,7 +163,7 @@
                        buttonYes, buttonNo);
 
     bool checkboxResult;
-    int result = createKMessageBox(dialog, QMessageBox::Information, text, strlist, 
+    int result = createKMessageBox(dialog, QMessageBox::Information, text, strlist,
                        dontAskAgainName.isEmpty() ? QString::null : i18n("Do not ask \
again"),  &checkboxResult);
 
@@ -199,12 +199,87 @@
 
     return Yes; // Default
 }
+int
+KMessageBox::questionYesNoCancel(QWidget *parent,
+                          const QString &text,
+                          const QString &caption,
+                          const QString &buttonYes,
+                          const QString &buttonNo,
+                          const QString &buttonCancel,
+                          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("Question") : caption,
+                       KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel,
+                       KDialogBase::Yes, KDialogBase::Cancel,
+                       parent, "questionYesNoCancel", true, true,
+                       buttonYes, buttonNo, buttonCancel);
+
+    bool checkboxResult;
+    int result = createKMessageBox(dialog, QMessageBox::Information
+, 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:
+         return Cancel;
+
+      default: // Huh?
+         break;
+    }
+
+    return Cancel; // Default
+}
 
 int
 KMessageBox::warningYesNo(QWidget *parent, const QString &text,
                           const QString &caption,
                           const QString &buttonYes,
-                          const QString &buttonNo, 
+                          const QString &buttonNo,
                           const QString &dontAskAgainName,
                           bool /*notify*/)
 {
@@ -271,10 +346,10 @@
 }
 
 int
-KMessageBox::warningContinueCancel(QWidget *parent, 
+KMessageBox::warningContinueCancel(QWidget *parent,
                                    const QString &text,
                                    const QString &caption,
-                                   const QString &buttonContinue, 
+                                   const QString &buttonContinue,
                                    const QString &dontAskAgainName,
                                    bool notify)
 {
@@ -286,7 +361,7 @@
 KMessageBox::warningContinueCancelList(QWidget *parent, const QString &text,
                              const QStringList &strlist,
                              const QString &caption,
-                             const QString &buttonContinue, 
+                             const QString &buttonContinue,
                              const QString &dontAskAgainName,
                              bool /*notify*/)
 {
@@ -313,7 +388,7 @@
                        buttonContinue, i18n("&Cancel"));
 
     bool checkboxResult;
-    int result = createKMessageBox(dialog, QMessageBox::Warning, text, strlist, 
+    int result = createKMessageBox(dialog, QMessageBox::Warning, text, strlist,
                        dontAskAgainName.isEmpty() ? QString::null : i18n("Do not ask \
again"),  &checkboxResult);
 
@@ -333,7 +408,7 @@
          }
          return Continue;
       }
-   
+
       case KDialogBase::No:
          return Cancel;
 
@@ -349,7 +424,7 @@
 KMessageBox::warningYesNoCancel(QWidget *parent, const QString &text,
                                 const QString &caption,
                                 const QString &buttonYes,
-                                const QString &buttonNo, 
+                                const QString &buttonNo,
                                 const QString &dontAskAgainName,
                                 bool /*notify*/)
 {
@@ -378,7 +453,7 @@
                        buttonYes, buttonNo);
 
     bool checkboxResult;
-    int result = createKMessageBox(dialog, QMessageBox::Warning, text, \
QStringList(),  +    int result = createKMessageBox(dialog, QMessageBox::Warning, \
                text, QStringList(),
                        dontAskAgainName.isEmpty() ? QString::null : i18n("Do not ask \
again"),  &checkboxResult);
 
@@ -504,7 +579,7 @@
 
     bool checkboxResult;
 
-    createKMessageBox(dialog, QMessageBox::Information, text, QStringList(), 
+    createKMessageBox(dialog, QMessageBox::Information, text, QStringList(),
 		dontShowAgainName.isEmpty() ? QString::null : i18n("Do not show this message \
again"),   &checkboxResult);
 
@@ -566,12 +641,15 @@
     return;
 }
 
-int KMessageBox::messageBox( QWidget *parent, int type, const QString &text, const \
QString &caption, const QString &buttonYes, const QString &buttonNo ) +int \
KMessageBox::messageBox( QWidget *parent, int type, const QString &text, const \
QString &caption, const QString &buttonYes, const QString &buttonNo, const QString \
&buttonCancel )  {
     switch (type) {
         case QuestionYesNo:
             return KMessageBox::questionYesNo( parent,
                                                text, caption, buttonYes, buttonNo );
+        case QuestionYesNoCancel:
+            return KMessageBox::questionYesNoCancel( parent,
+                                               text, caption, buttonYes, buttonNo, \
buttonCancel );  case WarningYesNo:
             return KMessageBox::warningYesNo( parent,
                                               text, caption, buttonYes, buttonNo );
diff -urN kde_ui.orig/kmessagebox.h kdeui/kmessagebox.h
--- kde_ui.orig/kmessagebox.h	Sun Oct  7 15:12:18 2001
+++ kdeui/kmessagebox.h	Wed Oct 31 00:12:00 2001
@@ -24,8 +24,8 @@
 class QWidget;
 class QStringList;
 
- /** 
-  * Easy message dialog box. 
+ /**
+  * Easy message dialog box.
   *
   * Provides convenience functions for some i18n'ed standard dialogs.
   *
@@ -40,17 +40,17 @@
    **/
  enum { Ok = 1, Cancel = 2, Yes = 3, No = 4, Continue = 5 };
  /**
-  * Display a simple "question" dialog. 
+  * Display a simple "question" dialog.
   *
-  * @param parent  If @p parent is 0, then the message box becomes an 
+  * @param parent  If @p parent is 0, then the message box becomes an
   *                application-global modal dialog box. If @p parent is a
   *                widget, the message box becomes modal relative to parent.
   * @param text    Message string. May contain newlines.
   * @param caption Message box title. The application name is added to
   *                the title. The default title is i18n("Question").
-  * @param buttonYes The text for the first button. 
+  * @param buttonYes The text for the first button.
   *                  The default is i18n("&Yes").
-  * @param buttonNo  The text for the second button. 
+  * @param buttonNo  The text for the second button.
   *                  The default is i18n("&No").
   * @param dontAskAgainName If provided, a checkbox is added with which
   *                further confirmation can be turned off.
@@ -60,23 +60,62 @@
   *
   * @return  'Yes' is returned if the Yes-button is pressed. 'No' is returned
   *          if the No-button is pressed.
-  * 
+  *
   * To be used for questions like "Do you have a printer?"
   *
   * The default button is "Yes". Pressing "Esc" selects "No".
   */
-  
+
  static int questionYesNo(QWidget *parent,
                           const QString &text,
                           const QString &caption = QString::null,
-                          const QString &buttonYes = QString::null,  
-                          const QString &buttonNo = QString::null, 
+                          const QString &buttonYes = QString::null,
+                          const QString &buttonNo = QString::null,
                           const QString &dontAskAgainName = QString::null,
                           bool notify=true);
  /**
-  * Display a "question" dialog with a listbox to show information to the user 
+  * Display a simple "question" dialog.
   *
-  * @param parent  If @p parent is 0, then the message box becomes an 
+  * @param parent  If @p parent is 0, then the message box becomes an
+  *                application-global modal dialog box. If @p parent is a
+  *                widget, the message box becomes modal relative to parent.
+  * @param text    Message string. May contain newlines.
+  * @param caption Message box title. The application name is added to
+  *                the title. The default title is i18n("Question").
+  * @param buttonYes The text for the first button.
+  *                  The default is i18n("&Yes").
+  * @param buttonNo  The text for the second button.
+  *                  The default is i18n("&No").
+  * @param buttonCancel The text for the third button.
+                        The default is i18n("&Cancel").
+  * @param dontAskAgainName If provided, a checkbox is added with which
+  *                further confirmation can be turned off.
+  *                The string is used to lookup and store the setting
+  *                in the applications config file.
+  * @param notify  Emit a @ref KNotifyClient event.
+  *
+  * @return  'Yes' is returned if the Yes-button is pressed. 'No' is returned
+  *          if the No-button is pressed.
+  *
+  * To be used for questions like "Do you want to discard the message or save it for \
later?", +	*
+  *
+  * The default button is "Yes". Pressing "Esc" selects "Cancel".
+  */
+
+  static int questionYesNoCancel(QWidget *parent,
+                          const QString &text,
+                          const QString &caption = QString::null,
+                          const QString &buttonYes = QString::null,
+                          const QString &buttonNo = QString::null,
+                          const QString &buttonCancel = QString::null,
+                          const QString &dontAskAgainName = QString::null,
+                          bool notify=true);
+
+ /**
+  * Display a "question" dialog with a listbox to show information to the user
+  *
+  * @param parent  If @p parent is 0, then the message box becomes an
   *                application-global modal dialog box. If @p parent is a
   *                widget, the message box becomes modal relative to parent.
   * @param text    Message string. May contain newlines.
@@ -84,9 +123,9 @@
   *                empty, it doesn't show any listbox, working as questionYesNo.
   * @param caption Message box title. The application name is added to
   *                the title. The default title is i18n("Question").
-  * @param buttonYes The text for the first button. 
+  * @param buttonYes The text for the first button.
   *                  The default is i18n("&Yes").
-  * @param buttonNo  The text for the second button. 
+  * @param buttonNo  The text for the second button.
   *                  The default is i18n("&No").
   * @param dontAskAgainName If provided, a checkbox is added with which
   *                further confirmation can be turned off.
@@ -96,34 +135,34 @@
   *
   * @return  'Yes' is returned if the Yes-button is pressed. 'No' is returned
   *          if the No-button is pressed.
-  * 
+  *
   * To be used for questions like "Do you really want to delete these files?"
   * And show the user exactly which files are going to be deleted in case
   * he presses "Yes"
   *
   * The default button is "Yes". Pressing "Esc" selects "No".
   */
- 
+
  static int questionYesNoList(QWidget *parent,
                           const QString &text,
                           const QStringList &strlist,
                           const QString &caption = QString::null,
                           const QString &buttonYes = QString::null,
-                          const QString &buttonNo = QString::null, 
+                          const QString &buttonNo = QString::null,
                           const QString &dontAskAgainName = QString::null,
                           bool notify=true);
  /**
-  * Display a "warning" dialog. 
+  * Display a "warning" dialog.
   *
-  * @param parent  If @p parent is 0, then the message box becomes an 
+  * @param parent  If @p parent is 0, then the message box becomes an
   *                application-global modal dialog box. If @p parent is a
   *                widget, the message box becomes modal relative to parent.
   * @param text    Message string. May contain newlines.
   * @param caption Message box title. The application name is added to
   *                the title. The default title is i18n("Warning").
-  * @param buttonYes The text for the first button. 
+  * @param buttonYes The text for the first button.
   *                  The default is i18n("&Yes").
-  * @param buttonNo  The text for the second button. 
+  * @param buttonNo  The text for the second button.
   *                  The default is i18n("&No").
   * @param dontAskAgainName If provided, a checkbox is added with which
   *                further confirmation can be turned off.
@@ -148,7 +187,7 @@
                          bool notify=true);
 
  /**
-  * Display a "warning" dialog. 
+  * Display a "warning" dialog.
   *
   * @param parent  If @p parent is 0, then the message box becomes an 
   *                application-global modal dialog box. If @p parent is a
@@ -156,7 +195,7 @@
   * @param text    Message string. May contain newlines.
   * @param caption Message box title. The application name is added to
   *                the title. The default title is i18n("Warning").
-  * @param buttonContinue The text for the first button. 
+  * @param buttonContinue The text for the first button.
   * @param dontAskAgainName If provided, a checkbox is added with which
   *                further confirmation can be turned off.
   *                The string is used to lookup and store the setting
@@ -165,7 +204,7 @@
   *
   * The second button always has the text "Cancel".
   *
-  * @return  @p Continue is returned if the Continue-button is pressed. 
+  * @return  @p Continue is returned if the Continue-button is pressed.
   *          @p Cancel is returned if the Cancel-button is pressed.
   *
   * To be used for questions like "You are about to Print. Are you sure?"
@@ -173,18 +212,18 @@
   *
   * The default button is buttonContinue. Pressing "Esc" selects "Cancel".
   */
- static int warningContinueCancel(QWidget *parent, 
+ static int warningContinueCancel(QWidget *parent,
                          const QString &text,
                          const QString &caption = QString::null,
-                         const QString &buttonContinue = QString::null, 
+                         const QString &buttonContinue = QString::null,
                          const QString &dontAskAgainName = QString::null,
                          bool notify=true );
 
 
  /**
-  * Display a "warning" dialog with a listbox to show information to the user. 
+  * Display a "warning" dialog with a listbox to show information to the user.
   *
-  * @param parent  If @p parent is 0, then the message box becomes an 
+  * @param parent  If @p parent is 0, then the message box becomes an
   *                application-global modal dialog box. If @p parent is a
   *                widget, the message box becomes modal relative to parent.
   * @param text    Message string. May contain newlines.
@@ -193,7 +232,7 @@
   *                as warningContinueCancel.
   * @param caption Message box title. The application name is added to
   *                the title. The default title is i18n("Warning").
-  * @param buttonContinue The text for the first button. 
+  * @param buttonContinue The text for the first button.
   * @param dontAskAgainName If provided, a checkbox is added with which
   *                further confirmation can be turned off.
   *                The string is used to lookup and store the setting
@@ -222,7 +261,7 @@
 
 
  /**
-  * Display a Yes/No/Cancel "warning" dialog. 
+  * Display a Yes/No/Cancel "warning" dialog.
   *
   * @param parent  If @p parent is 0, then the message box becomes an 
   *                application-global modal dialog box. If @p parent is a
@@ -237,7 +276,7 @@
   * @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). 
+  *                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 @ref KNotifyClient event.
@@ -257,15 +296,15 @@
   static int warningYesNoCancel(QWidget *parent,
                                 const QString &text,
                                 const QString &caption = QString::null,
-                                const QString &buttonYes = QString::null,  
-                                const QString &buttonNo = QString::null, 
+                                const QString &buttonYes = QString::null,
+                                const QString &buttonNo = QString::null,
                                 const QString &dontAskAgainName = QString::null,
                                 bool notify=true);
 
  /**
-  * Display an "Error" dialog. 
+  * Display an "Error" dialog.
   *
-  * @param parent  If @p parent is 0, then the message box becomes an 
+  * @param parent  If @p parent is 0, then the message box becomes an
   *                application-global modal dialog box. If @p parent is a
   *                widget, the message box becomes modal relative to parent.
   * @param text    Message string. May contain newlines.
@@ -286,13 +325,13 @@
   */
   
   static void error(QWidget *parent, 
-                    const QString &text, 
+                    const QString &text,
                     const QString &caption = QString::null, bool notify=true);
 
  /**
   * Displays an "Error" dialog with a "Details >>" button.
   *
-  * @param parent  If @p parent is 0, then the message box becomes an 
+  * @param parent  If @p parent is 0, then the message box becomes an
   *                application-global modal dialog box. If @p parent is a
   *                widget, the message box becomes modal relative to parent.
   * @param text    Message string. May contain newlines.
@@ -306,25 +345,25 @@
   *
   * The @p details message can conatin additional information about
   * the problem and can be shown on request to advanced/interested users.
-  * 
+  *
   * If your program detects the action specified by the user is somehow
   * not allowed, this should never be reported with error(). Use sorry()
-  * instead to explain to the user that this action is not allowed. 
+  * instead to explain to the user that this action is not allowed.
   *
   * The default button is "&OK". Pressing "Esc" selects the OK-button.
   *
   * NOTE: The OK button will always have the i18n'ed text '&OK'.
   */
-  static void detailedError(QWidget *parent, 
+  static void detailedError(QWidget *parent,
                     const QString &text,
                     const QString &details,
                     const QString &caption = QString::null, bool notify=true);
 
 
  /**
-  * Display an "Sorry" dialog. 
+  * Display an "Sorry" dialog.
   *
-  * @param parent  If @p parent is 0, then the message box becomes an 
+  * @param parent  If @p parent is 0, then the message box becomes an
   *                application-global modal dialog box. If @p parent is a
   *                widget, the message box becomes modal relative to parent.
   * @param text    Message string. May contain newlines.
@@ -335,22 +374,22 @@
   * Either your program messed up and asks for understanding
   * or your user did something stupid.
   *
-  * To be used for small problems like 
+  * To be used for small problems like
   * "Sorry, I can't find the file you specified."
   *
   * The default button is "&OK". Pressing "Esc" selects the OK-button.
   *
   * NOTE: The ok button will always have the i18n'ed text '&OK'.
   */
-  
-  static void sorry(QWidget *parent, 
+
+  static void sorry(QWidget *parent,
                     const QString &text,
                     const QString &caption = QString::null, bool notify=true);
 
  /**
   * Displays a "Sorry" dialog with a "Details >>" button.
   *
-  * @param parent  If @p parent is 0, then the message box becomes an 
+  * @param parent  If @p parent is 0, then the message box becomes an
   *                application-global modal dialog box. If @p parent is a
   *                widget, the message box becomes modal relative to parent.
   * @param text    Message string. May contain newlines.
@@ -366,7 +405,7 @@
   * "Sorry, I can't find the file you specified."
   *
   * And then @p details can contain something like
-  * "foobar.txt was not found in any of 
+  * "foobar.txt was not found in any of
   *  the following directories:
   *  /usr/bin,/usr/local/bin,/usr/sbin"
   *
@@ -381,7 +420,7 @@
                     const QString &caption = QString::null, bool notify=true);
 
  /**
-  * Display an "Information" dialog. 
+  * Display an "Information" dialog.
   *
   * @param parent  If @p parent is 0, then the message box becomes an 
   *                application-global modal dialog box. If @p parent is a
@@ -417,11 +456,11 @@
    * @p dontShowAgainName feature of the information dialog.
    */
   static void enableAllMessages();
-  
+
   /**
-   * Display an "About" dialog. 
+   * Display an "About" dialog.
    *
-   * @param parent  If @p parent is 0, then the message box becomes an 
+   * @param parent  If @p parent is 0, then the message box becomes an
    *                application-global modal dialog box. If @p parent is a
    *                widget, the message box becomes modal relative to parent.
    * @param text    Message string. May contain newlines.
@@ -433,7 +472,7 @@
    * Your program wants to show some general information about the application
    * like the authors's names and email addresses.
    *
-   * The default button is "&OK". 
+   * The default button is "&OK".
    *
    *  NOTE: The ok button will always have the i18n'ed text '&OK'.
    */
@@ -441,14 +480,15 @@
 		    const QString& text,
 		    const QString& caption = QString::null, bool notify=true);
 
-  enum { QuestionYesNo = 1, 
-         WarningYesNo = 2, 
-         WarningContinueCancel = 3, 
-         WarningYesNoCancel = 4, 
+  enum { QuestionYesNo = 1,
+         WarningYesNo = 2,
+         WarningContinueCancel = 3,
+         WarningYesNoCancel = 4,
          Information = 5,
-         // Reserved for: SSLMessageBox = 6 
+         // Reserved for: SSLMessageBox = 6
          Sorry = 7,
-         Error = 8
+         Error = 8,
+         QuestionYesNoCancel = 9,
          };
 
     /**
@@ -456,7 +496,7 @@
      *
      * @param parent  If @p parent is 0, then the message box becomes an
      *                application-global modal dialog box. If @p parent is a
-     *                widget, the message box becomes modal relative to parent.     
+     *                widget, the message box becomes modal relative to parent.
      * @param type type of message box: QuestionYesNo, WarningYesNo, \
                WarningContinueCancel...
      * @param text Message string. May contain newlines.
      * @param caption Message box title.
@@ -471,10 +511,11 @@
     static int messageBox( QWidget *parent, int type, const QString &text,
                     const QString &caption = QString::null,
                     const QString &buttonYes = QString::null,
-                    const QString &buttonNo = QString::null );
+                    const QString &buttonNo = QString::null,
+                    const QString &buttonCancel = QString::null);
 
     /*
-     * Like @ref messageBox 
+     * Like @ref messageBox
      *
      * Only for message boxes of type Information, Sorry or Error.
      *


>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


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

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