Mercurial > trustbridge
diff ui/trayicon.cpp @ 969:c096881e8ed0
(issue50) Make message box a member variable
This only shows the message box again if no old
message box still exists.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 28 Aug 2014 14:43:47 +0200 |
parents | 4efd6378c001 |
children | c80777457133 |
line wrap: on
line diff
--- 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; +}