From 729adf06c3dc2ba055793e5647c4da0beb829c9c Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Fri, 4 Jan 2008 20:11:32 +0000 Subject: [PATCH] - Fixed systray integration when qbittorrent is launched on system startup --- Changelog | 1 + TODO | 3 +++ src/GUI.cpp | 35 ++++++++++++++++++++++++++++++++++- src/GUI.h | 2 ++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 27041a6e0..ea33357ad 100644 --- a/Changelog +++ b/Changelog @@ -58,6 +58,7 @@ - BUGFIX: search plugin update - do not display only last version changelog - BUGFIX: Search plugin update - fixed missing new lines in changelog - BUGFIX: The number of search results was not reset when clicking on 'Clear' button + - BUGFIX: Fixed systray integration when qbittorrent is launched on system startup - BUGFIX: Update torrent progress when its content changed (filtered files) - BUGFIX: Improved the way menu icons are installed to avoid problems on some systems - BUGFIX: Improved incremental download diff --git a/TODO b/TODO index 76f173f82..9caee29d8 100644 --- a/TODO +++ b/TODO @@ -44,3 +44,6 @@ * free disk space on selected drive * free disk space after torrent download (and/or torrent size) +rc11 -> final? changelog: +BUGFIX: Fixed systray integration when qbittorrent is launched on system startup + diff --git a/src/GUI.cpp b/src/GUI.cpp index 92d01b80a..baee232a7 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -61,14 +61,21 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent v0.x").arg(QString::fromUtf8(VERSION))); QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); systrayIntegration = settings.value(QString::fromUtf8("Preferences/General/SystrayEnabled"), true).toBool(); + systrayCreator = 0; // Create tray icon if (QSystemTrayIcon::isSystemTrayAvailable()) { if(systrayIntegration) { createTrayIcon(); } }else{ + if(systrayIntegration) { + // May be system startup, check again later + systrayCreator = new QTimer(this); + connect(systrayCreator, SIGNAL(timeout()), this, SLOT(createSystrayDelayed())); + systrayCreator->start(1000); + } systrayIntegration = false; - qDebug("Info: System tray unavailable\n"); + qDebug("Info: System tray unavailable"); } // Setting icons this->setWindowIcon(QIcon(QString::fromUtf8(":/Icons/qbittorrent32.png"))); @@ -176,6 +183,9 @@ GUI::~GUI() { delete downloadingTorrentTab; delete finishedTorrentTab; delete checkConnect; + if(systrayCreator) { + delete systrayCreator; + } if(systrayIntegration) { delete myTrayIcon; delete myTrayIconMenu; @@ -1183,6 +1193,29 @@ void GUI::downloadFromURLList(const QStringList& urls) { * * *****************************************************/ +void GUI::createSystrayDelayed() { + static int timeout = 10; + if(QSystemTrayIcon::isSystemTrayAvailable()) { + // Ok, systray integration is now supported + // Create systray icon + createTrayIcon(); + systrayIntegration = true; + delete systrayCreator; + systrayCreator = 0; + } else { + if(timeout) { + // Retry a bit later + systrayCreator->start(1000); + --timeout; + } else { + // Timed out, apparently system really does not + // support systray icon + delete systrayCreator; + systrayCreator = 0; + } + } +} + void GUI::createTrayIcon() { // Tray icon #ifdef Q_WS_WIN diff --git a/src/GUI.h b/src/GUI.h index ca7c8b4cc..fef32405d 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -59,6 +59,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ QTabWidget *tabs; options_imp *options; QSystemTrayIcon *myTrayIcon; + QTimer *systrayCreator; QMenu *myTrayIconMenu; DownloadingTorrents *downloadingTorrentTab; FinishedTorrents *finishedTorrentTab; @@ -105,6 +106,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ void updateFinishedTorrentNumber(unsigned int nb); void fullDiskError(QTorrentHandle& h) const; void handleDownloadFromUrlFailure(QString, QString) const; + void createSystrayDelayed(); // Keyboard shortcuts void createKeyboardShortcuts(); void displayDownTab() const;