From f62e09ce8863909ceb9b8f59db6c5c5e4ba01d38 Mon Sep 17 00:00:00 2001 From: jlh Date: Sun, 6 Jul 2008 00:56:21 +0200 Subject: [PATCH] Delay error message when no system tray is present When configuring a desktop environment to start Skype Call Recording automatically on start-up, it could happen the it was started before the environment provided a system tray, causing it to fail with an error message. QSystemTrayIcon explicitely allows to create the icon before the tray becomes available as it will then take care of adding it as soon as possible. The error message now appears only if the system tray is still not available after 10 seconds. Note that this code was buggy anyway: If no system tray was detected, the signal requestQuitNoConfirmation() was emitted, which did nothing because it wasn't connected to anything yet (no way it could, since TrayIcon was just only constructed). --- trayicon.cpp | 19 ++++++++++++++----- trayicon.h | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/trayicon.cpp b/trayicon.cpp index 793a5a8..8599d67 100644 --- a/trayicon.cpp +++ b/trayicon.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include "trayicon.h" #include "common.h" @@ -34,11 +35,8 @@ TrayIcon::TrayIcon(QObject *p) : QSystemTrayIcon(p) { if (!QSystemTrayIcon::isSystemTrayAvailable()) { - QMessageBox::critical(NULL, PROGRAM_NAME " - Error", - PROGRAM_NAME " cannot start, because it requires a system tray. None was detected. " - "(TODO: Make this work even without a system tray.)"); - emit requestQuitNoConfirmation(); - return; + debug("Warning: No system tray detected. Will check again in 10 seconds."); + QTimer::singleShot(10000, this, SLOT(checkTrayPresence())); } smStart = new QSignalMapper(this); @@ -75,6 +73,17 @@ TrayIcon::~TrayIcon() { delete menu; } +void TrayIcon::checkTrayPresence() { + if (QSystemTrayIcon::isSystemTrayAvailable()) { + debug("System tray now present, all ok."); + } else { + QMessageBox::critical(NULL, PROGRAM_NAME " - Error", + PROGRAM_NAME " cannot start, because it requires a system tray. None was detected. " + "(TODO: Make this work even without a system tray.)"); + emit requestQuitNoConfirmation(); + } +} + void TrayIcon::setColor(bool color) { setIcon(QIcon(color ? ":/icon.png" : ":/icongray.png")); } diff --git a/trayicon.h b/trayicon.h index ec23b9f..107c246 100644 --- a/trayicon.h +++ b/trayicon.h @@ -60,6 +60,7 @@ public slots: void stoppedRecording(int); private slots: + void checkTrayPresence(); void activate(QSystemTrayIcon::ActivationReason); private: -- 2.11.4.GIT