mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-07 22:22:45 -04:00
Reworked notification code in system tray.
Added a base class and a possibility for the main dialogs and the plugins (derived from MainPage) to provide a notifier. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5381 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
049b4bd577
commit
b21e66241b
30 changed files with 1040 additions and 539 deletions
retroshare-gui/src/gui/common
94
retroshare-gui/src/gui/common/UserNotify.cpp
Normal file
94
retroshare-gui/src/gui/common/UserNotify.cpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
#include <QMenu>
|
||||
#include "UserNotify.h"
|
||||
|
||||
UserNotify::UserNotify(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
mMainIcon = NULL;
|
||||
mTrayIcon = NULL;
|
||||
mNotifyIcon = NULL;
|
||||
newCount = 0;
|
||||
}
|
||||
|
||||
void UserNotify::initialize(QAction *mainAction)
|
||||
{
|
||||
mMainIcon = mainAction;
|
||||
}
|
||||
|
||||
void UserNotify::createIcons(QMenu *notifyMenu)
|
||||
{
|
||||
#define DELETE_OBJECT(x) if (x) { delete(x); x = NULL; }
|
||||
|
||||
/* Create systray icons or actions */
|
||||
if (notifyEnabled()) {
|
||||
if (notifyCombined()) {
|
||||
DELETE_OBJECT(mTrayIcon);
|
||||
|
||||
if (mNotifyIcon == NULL) {
|
||||
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(mTrayIcon);
|
||||
DELETE_OBJECT(mNotifyIcon);
|
||||
}
|
||||
|
||||
#undef DELETE_OBJECT
|
||||
}
|
||||
|
||||
void UserNotify::updateIcon()
|
||||
{
|
||||
unsigned int count = getNewCount();
|
||||
|
||||
if (mMainIcon) {
|
||||
mMainIcon->setIcon(getMainIcon(count > 0));
|
||||
}
|
||||
|
||||
if (mTrayIcon) {
|
||||
if (count) {
|
||||
mTrayIcon->setToolTip("RetroShare\n" + getTrayMessage(count > 1).arg(count));
|
||||
mTrayIcon->show();
|
||||
} else {
|
||||
mTrayIcon->hide();
|
||||
}
|
||||
}
|
||||
|
||||
if (mNotifyIcon) {
|
||||
mNotifyIcon->setData(count);
|
||||
if (count) {
|
||||
mNotifyIcon->setText(getNotifyMessage(count > 1).arg(count));
|
||||
mNotifyIcon->setVisible(true);
|
||||
} else {
|
||||
mNotifyIcon->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (newCount != count) {
|
||||
emit countChanged();
|
||||
}
|
||||
|
||||
count = newCount;
|
||||
}
|
||||
|
||||
QString UserNotify::getTrayMessage(bool plural)
|
||||
{
|
||||
return plural ? tr("You have %1 new messages") : tr("You have %1 new message");
|
||||
}
|
||||
|
||||
QString UserNotify::getNotifyMessage(bool plural)
|
||||
{
|
||||
return plural ? tr("%1 new messages") : tr("%1 new message");
|
||||
}
|
||||
|
||||
void UserNotify::trayIconClicked(QSystemTrayIcon::ActivationReason e)
|
||||
{
|
||||
if (e == QSystemTrayIcon::Trigger || e == QSystemTrayIcon::DoubleClick) {
|
||||
iconClicked();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue