Added option to disable/enable tray icon explicitly + some details.

This commit is contained in:
Martin Rotter 2013-06-19 15:48:33 +02:00
parent b0d5ddecd9
commit 0689353540
5 changed files with 32 additions and 7 deletions

View file

@ -46,6 +46,13 @@ void FormMain::quit() {
qApp->quit(); qApp->quit();
} }
void FormMain::display() {
setWindowState(windowState() & ~Qt::WindowMinimized);
raise();
activateWindow();
QtSingleApplication::alert(this);
}
void FormMain::cleanupResources() { void FormMain::cleanupResources() {
qDebug("Cleaning up resources before the application exits."); qDebug("Cleaning up resources before the application exits.");
} }

View file

@ -28,6 +28,7 @@ class FormMain : public QMainWindow {
public slots: public slots:
void processExecutionMessage(const QString &message); void processExecutionMessage(const QString &message);
void quit(); void quit();
void display();
protected slots: protected slots:
void cleanupResources(); void cleanupResources();

View file

@ -92,6 +92,12 @@ void FormSettings::saveInterface() {
// TODO: Switch tray icon here (destroy it/create it) and // TODO: Switch tray icon here (destroy it/create it) and
// if icon is should be destroyed and no main window is visible, // if icon is should be destroyed and no main window is visible,
// then show main window and then destroy tray icon. // 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. // Save selected icon theme.

View file

@ -7,11 +7,11 @@
#include "core/defs.h" #include "core/defs.h"
QPointer<SystemTrayIcon> SystemTrayIcon::m_trayIcon; QPointer<SystemTrayIcon> SystemTrayIcon::s_trayIcon;
SystemTrayIcon::SystemTrayIcon(const QString &normal_icon, SystemTrayIcon::SystemTrayIcon(const QString &normal_icon,
const QString &plain_icon, const QString &plain_icon,
QObject *parent) FormMain *parent)
: QSystemTrayIcon(parent), m_normalIcon(normal_icon), m_plainIcon(plain_icon) { : QSystemTrayIcon(parent), m_normalIcon(normal_icon), m_plainIcon(plain_icon) {
qDebug("Creating SystemTrayIcon instance."); qDebug("Creating SystemTrayIcon instance.");
@ -35,13 +35,21 @@ bool SystemTrayIcon::isSystemTrayActivated() {
} }
SystemTrayIcon *SystemTrayIcon::getInstance() { SystemTrayIcon *SystemTrayIcon::getInstance() {
if (m_trayIcon.isNull()) { if (s_trayIcon.isNull()) {
m_trayIcon = new SystemTrayIcon(APP_ICON_PATH, s_trayIcon = new SystemTrayIcon(APP_ICON_PATH,
APP_ICON_PLAIN_PATH, APP_ICON_PLAIN_PATH,
FormMain::getInstance()); 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() { void SystemTrayIcon::show_private() {

View file

@ -5,12 +5,14 @@
#include <QPointer> #include <QPointer>
class FormMain;
class SystemTrayIcon : public QSystemTrayIcon { class SystemTrayIcon : public QSystemTrayIcon {
Q_OBJECT Q_OBJECT
public: public:
explicit SystemTrayIcon(const QString &normal_icon, explicit SystemTrayIcon(const QString &normal_icon,
const QString &plain_icon, const QString &plain_icon,
QObject *parent = 0); FormMain *parent = 0);
~SystemTrayIcon(); ~SystemTrayIcon();
// Returns true if tray icon CAN be constructed on this machine. // 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 // TODO: Implement method for manual clearing of the tray icon. Creating of tray icon
// handled by getInstance(). // handled by getInstance().
static void deleteInstance();
signals: signals:
public slots: public slots:
@ -41,7 +44,7 @@ class SystemTrayIcon : public QSystemTrayIcon {
QString m_normalIcon; QString m_normalIcon;
QString m_plainIcon; QString m_plainIcon;
static QPointer<SystemTrayIcon> m_trayIcon; static QPointer<SystemTrayIcon> s_trayIcon;
}; };
#endif // SYSTEMTRAYICON_H #endif // SYSTEMTRAYICON_H