From 9953b3b6409b9eaec572d2acdce16a8d6ba10098 Mon Sep 17 00:00:00 2001 From: thunder2 Date: Wed, 24 Oct 2012 08:34:42 +0000 Subject: [PATCH] Fixed switching between combined and not combined tray icon notify with available messages. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5719 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/MainWindow.cpp | 1 + retroshare-gui/src/gui/common/UserNotify.cpp | 24 ++++++++++++-------- retroshare-gui/src/gui/common/UserNotify.h | 4 ++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 96198319c..22f43007a 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -492,6 +492,7 @@ void MainWindow::createNotifyIcons() userNotify->createIcons(notifyMenu); userNotify->updateIcon(); } + updateTrayCombine(); } const QList &MainWindow::getUserNotifyList() diff --git a/retroshare-gui/src/gui/common/UserNotify.cpp b/retroshare-gui/src/gui/common/UserNotify.cpp index b182636fa..096cf6a63 100644 --- a/retroshare-gui/src/gui/common/UserNotify.cpp +++ b/retroshare-gui/src/gui/common/UserNotify.cpp @@ -32,14 +32,14 @@ UserNotify::UserNotify(QObject *parent) : mMainAction = NULL; mTrayIcon = NULL; mNotifyIcon = NULL; - newCount = 0; + mNewCount = 0; } void UserNotify::initialize(QToolBar *mainToolBar, QAction *mainAction) { mMainAction = mainAction; if (mMainAction) { - buttonText = mMainAction->text(); + mButtonText = mMainAction->text(); if (mainToolBar) { mMainToolButton = dynamic_cast(mainToolBar->widgetForAction(mMainAction)); } @@ -59,11 +59,15 @@ void UserNotify::createIcons(QMenu *notifyMenu) mNotifyIcon = notifyMenu->addAction(getIcon(), "", this, SLOT(trayIconClicked())); mNotifyIcon->setVisible(false); } - } else if (mTrayIcon == NULL) { - /* Create the tray icon for messages */ - mTrayIcon = new QSystemTrayIcon(this); - mTrayIcon->setIcon(getIcon()); - connect(mTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason))); + } else { + DELETE_OBJECT(mNotifyIcon); + + if (mTrayIcon == NULL) { + /* Create the tray icon for messages */ + mTrayIcon = new QSystemTrayIcon(this); + mTrayIcon->setIcon(getIcon()); + connect(mTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayIconClicked(QSystemTrayIcon::ActivationReason))); + } } } else { DELETE_OBJECT(mTrayIcon); @@ -79,7 +83,7 @@ void UserNotify::updateIcon() if (mMainAction) { mMainAction->setIcon(getMainIcon(count > 0)); - mMainAction->setText((count > 0) ? QString("%1 (%2)").arg(buttonText).arg(count) : buttonText); + mMainAction->setText((count > 0) ? QString("%1 (%2)").arg(mButtonText).arg(count) : mButtonText); QFont font = mMainAction->font(); font.setBold(count > 0); @@ -113,11 +117,11 @@ void UserNotify::updateIcon() } } - if (newCount != count) { + if (mNewCount != count) { emit countChanged(); } - newCount = count; + mNewCount = count; } QString UserNotify::getTrayMessage(bool plural) diff --git a/retroshare-gui/src/gui/common/UserNotify.h b/retroshare-gui/src/gui/common/UserNotify.h index 8f2cccbe7..2637b5a6d 100644 --- a/retroshare-gui/src/gui/common/UserNotify.h +++ b/retroshare-gui/src/gui/common/UserNotify.h @@ -67,8 +67,8 @@ private: QAction *mMainAction; QSystemTrayIcon *mTrayIcon; QAction *mNotifyIcon; - unsigned int newCount; - QString buttonText; + unsigned int mNewCount; + QString mButtonText; }; #endif // USERNOTIFY_H