[PATCH 1 of 2] (issue50) Make message box a member variable

Wald Commits scm-commit at wald.intevation.org
Thu Aug 28 14:50:10 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1409229827 -7200
# Node ID c096881e8ed08e88893ec2fd5b6d3ac707a4a870
# Parent  5e43b9a4e92613c55c39aa5c347d1d05790a9e93
(issue50) Make message box a member variable

    This only shows the message box again if no old
    message box still exists.

diff -r 5e43b9a4e926 -r c096881e8ed0 ui/trayicon.cpp
--- a/ui/trayicon.cpp	Thu Aug 28 12:57:35 2014 +0200
+++ b/ui/trayicon.cpp	Thu Aug 28 14:43:47 2014 +0200
@@ -16,7 +16,8 @@
 
 TrayIcon::TrayIcon (QObject *parent) :
     QSystemTrayIcon (parent),
-    useAlt(false)
+    useAlt(false),
+    mMessageBox(NULL)
 {
     if (QSystemTrayIcon::isSystemTrayAvailable() &&
         qgetenv("XDG_CURRENT_DESKTOP") != "Unity") {
@@ -41,11 +42,19 @@
         QSystemTrayIcon::showMessage(title, msg, msg_icon, msecs);
         return;
     }
-    QMessageBox *theMessage = new QMessageBox (QMessageBox::Information,
-            title, msg, QMessageBox::Ok | QMessageBox::No, qobject_cast<QWidget*>(parent()));
-    theMessage->setIconPixmap (icon().pixmap(theMessage->iconPixmap().size()));
-    theMessage->button(QMessageBox::Ok)->setText (tr("Install update"));
-    theMessage->button(QMessageBox::No)->setText (tr("Remind me later"));
-    connect(theMessage->button(QMessageBox::Ok), SIGNAL(clicked()), this, SIGNAL(messageClicked()));
-    theMessage->show();
+    if (!mMessageBox) {
+        mMessageBox = new QMessageBox (QMessageBox::Information,
+                                       title, msg, QMessageBox::Ok | QMessageBox::No,
+                                       qobject_cast<QWidget*>(parent()));
+        connect(mMessageBox->button(QMessageBox::Ok), SIGNAL(clicked()), this, SIGNAL(messageClicked()));
+        connect(mMessageBox, SIGNAL(destroyed()), this, SLOT(messageDestroyed()));
+    }
+    mMessageBox->setIconPixmap (icon().pixmap(mMessageBox->iconPixmap().size()));
+    mMessageBox->button(QMessageBox::Ok)->setText (tr("Install update"));
+    mMessageBox->button(QMessageBox::No)->setText (tr("Remind me later"));
+    mMessageBox->show();
 }
+
+void TrayIcon::messageDestroyed() {
+    mMessageBox = NULL;
+}
diff -r 5e43b9a4e926 -r c096881e8ed0 ui/trayicon.h
--- a/ui/trayicon.h	Thu Aug 28 12:57:35 2014 +0200
+++ b/ui/trayicon.h	Thu Aug 28 14:43:47 2014 +0200
@@ -20,6 +20,9 @@
  * This class should become obsolete once Qt improves the support for
  * StatusNotifier icons that are used in Plasma 5 and Unity.
  */
+
+class QMessageBox;
+
 class TrayIcon :  public QSystemTrayIcon
 {
     Q_OBJECT
@@ -32,8 +35,12 @@
 public Q_SLOTS:
     void showMessage(const QString &title, const QString &msg,
                      QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int msecs = 10000);
+private Q_SLOTS:
+    void messageDestroyed();
+
 private:
     bool useAlt;
+    QMessageBox *mMessageBox;
 };
 
 #endif // TRAYICON_H


More information about the Trustbridge-commits mailing list