31 #include "gui/systemtrayicon.h"
33 #include "definitions/definitions.h"
34 #include "miscellaneous/settings.h"
35 #include "miscellaneous/application.h"
42 TrayIconMenu::TrayIconMenu(
const QString &title, QWidget *parent)
43 : QMenu(title, parent) {
46 TrayIconMenu::~TrayIconMenu() {
49 bool TrayIconMenu::event(QEvent *event) {
50 if (Application::activeModalWidget() != NULL && event->type() == QEvent::Show) {
51 QTimer::singleShot(0,
this, SLOT(hide()));
52 qApp->trayIcon()->showMessage(APP_LONG_NAME,
53 tr(
"Close opened modal dialogs first."),
54 QSystemTrayIcon::Warning);
57 return QMenu::event(event);
62 : QSystemTrayIcon(parent),
63 m_bubbleClickTarget(NULL),
64 m_bubbleClickSlot(NULL) {
65 qDebug(
"Creating SystemTrayIcon instance.");
70 connect(
this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
71 this, SLOT(onActivated(QSystemTrayIcon::ActivationReason)));
74 SystemTrayIcon::~SystemTrayIcon() {
75 qDebug(
"Destroying SystemTrayIcon instance.");
79 const QString &message,
80 QSystemTrayIcon::MessageIcon icon,
81 int milliseconds_timeout_hint,
82 QObject *click_target,
83 const char *click_slot) {
84 if (m_bubbleClickTarget != NULL && m_bubbleClickSlot != NULL) {
86 disconnect(
this, SIGNAL(messageClicked()), m_bubbleClickTarget, m_bubbleClickSlot);
89 m_bubbleClickSlot = (
char*) click_slot;
90 m_bubbleClickTarget = click_target;
92 if (click_target != NULL && click_slot != NULL) {
94 connect(
this, SIGNAL(messageClicked()), click_target, click_slot);
99 QSystemTrayIcon::showMessage(title, message, icon, milliseconds_timeout_hint);
103 return QSystemTrayIcon::isSystemTrayAvailable() && QSystemTrayIcon::supportsMessages();
106 void SystemTrayIcon::showPrivate() {
108 QSystemTrayIcon::show();
109 qDebug(
"Tray icon displayed.");
113 #if defined(Q_OS_WIN)
115 qDebug(
"Showing tray icon immediately.");
119 qDebug(
"Showing tray icon with 1000 ms delay.");
120 QTimer::singleShot(TRAY_ICON_DELAY,
this, SLOT(showPrivate()));
123 qApp->setQuitOnLastWindowClosed(
false);
126 void SystemTrayIcon::onActivated(QSystemTrayIcon::ActivationReason reason) {
127 #if defined(Q_OS_WIN)
128 if (Application::activeModalWidget() != NULL && reason != Unknown) {
129 qApp->trayIcon()->showMessage(APP_LONG_NAME,
130 tr(
"Close opened modal dialogs first."),
131 QSystemTrayIcon::Warning);
136 case QSystemTrayIcon::Trigger:
SystemTrayIcon(const QString &icon, QObject *parent=0)
Constructor.
void leftMouseClicked()
Emitted if user clicks tray icon with left mouse button.
void showMessage(const QString &title, const QString &message, MessageIcon icon=Information, int milliseconds_timeout_hint=TRAY_ICON_BUBBLE_TIMEOUT, QObject *click_target=NULL, const char *click_slot=NULL)
Displays new balloon tip with message.
void show()
Displays tray icon.
static bool isSystemTrayAvailable()
Indicates whether tray icon is supported.