Added option to disable/enable tray icon explicitly + some details.
This commit is contained in:
parent
b0d5ddecd9
commit
0689353540
5 changed files with 32 additions and 7 deletions
|
@ -46,6 +46,13 @@ void FormMain::quit() {
|
|||
qApp->quit();
|
||||
}
|
||||
|
||||
void FormMain::display() {
|
||||
setWindowState(windowState() & ~Qt::WindowMinimized);
|
||||
raise();
|
||||
activateWindow();
|
||||
QtSingleApplication::alert(this);
|
||||
}
|
||||
|
||||
void FormMain::cleanupResources() {
|
||||
qDebug("Cleaning up resources before the application exits.");
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ class FormMain : public QMainWindow {
|
|||
public slots:
|
||||
void processExecutionMessage(const QString &message);
|
||||
void quit();
|
||||
void display();
|
||||
|
||||
protected slots:
|
||||
void cleanupResources();
|
||||
|
|
|
@ -92,6 +92,12 @@ void FormSettings::saveInterface() {
|
|||
// TODO: Switch tray icon here (destroy it/create it) and
|
||||
// if icon is should be destroyed and no main window is visible,
|
||||
// then show main window and then destroy tray icon.
|
||||
if (Settings::getInstance()->value(APP_CFG_GUI, "use_tray_icon", true).toBool()) {
|
||||
SystemTrayIcon::getInstance()->show();
|
||||
}
|
||||
else {
|
||||
SystemTrayIcon::deleteInstance();
|
||||
}
|
||||
}
|
||||
|
||||
// Save selected icon theme.
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
#include "core/defs.h"
|
||||
|
||||
|
||||
QPointer<SystemTrayIcon> SystemTrayIcon::m_trayIcon;
|
||||
QPointer<SystemTrayIcon> SystemTrayIcon::s_trayIcon;
|
||||
|
||||
SystemTrayIcon::SystemTrayIcon(const QString &normal_icon,
|
||||
const QString &plain_icon,
|
||||
QObject *parent)
|
||||
FormMain *parent)
|
||||
: QSystemTrayIcon(parent), m_normalIcon(normal_icon), m_plainIcon(plain_icon) {
|
||||
qDebug("Creating SystemTrayIcon instance.");
|
||||
|
||||
|
@ -35,13 +35,21 @@ bool SystemTrayIcon::isSystemTrayActivated() {
|
|||
}
|
||||
|
||||
SystemTrayIcon *SystemTrayIcon::getInstance() {
|
||||
if (m_trayIcon.isNull()) {
|
||||
m_trayIcon = new SystemTrayIcon(APP_ICON_PATH,
|
||||
if (s_trayIcon.isNull()) {
|
||||
s_trayIcon = new SystemTrayIcon(APP_ICON_PATH,
|
||||
APP_ICON_PLAIN_PATH,
|
||||
FormMain::getInstance());
|
||||
}
|
||||
|
||||
return m_trayIcon;
|
||||
return s_trayIcon;
|
||||
}
|
||||
|
||||
void SystemTrayIcon::deleteInstance() {
|
||||
if (!s_trayIcon.isNull()) {
|
||||
qDebug("Disabling tray icon and raising main application window.");
|
||||
static_cast<FormMain*>((*s_trayIcon).parent())->display();
|
||||
delete s_trayIcon.data();
|
||||
}
|
||||
}
|
||||
|
||||
void SystemTrayIcon::show_private() {
|
||||
|
|
|
@ -5,12 +5,14 @@
|
|||
#include <QPointer>
|
||||
|
||||
|
||||
class FormMain;
|
||||
|
||||
class SystemTrayIcon : public QSystemTrayIcon {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SystemTrayIcon(const QString &normal_icon,
|
||||
const QString &plain_icon,
|
||||
QObject *parent = 0);
|
||||
FormMain *parent = 0);
|
||||
~SystemTrayIcon();
|
||||
|
||||
// Returns true if tray icon CAN be constructed on this machine.
|
||||
|
@ -29,6 +31,7 @@ class SystemTrayIcon : public QSystemTrayIcon {
|
|||
|
||||
// TODO: Implement method for manual clearing of the tray icon. Creating of tray icon
|
||||
// handled by getInstance().
|
||||
static void deleteInstance();
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
@ -41,7 +44,7 @@ class SystemTrayIcon : public QSystemTrayIcon {
|
|||
QString m_normalIcon;
|
||||
QString m_plainIcon;
|
||||
|
||||
static QPointer<SystemTrayIcon> m_trayIcon;
|
||||
static QPointer<SystemTrayIcon> s_trayIcon;
|
||||
};
|
||||
|
||||
#endif // SYSTEMTRAYICON_H
|
||||
|
|
Loading…
Add table
Reference in a new issue