mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 14:04:23 +00:00
- Fixed systray integration when qbittorrent is launched on system startup
This commit is contained in:
parent
85796d9c2c
commit
5e86c8a14d
35
src/GUI.cpp
35
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)));
|
setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent v0.x").arg(QString::fromUtf8(VERSION)));
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||||||
systrayIntegration = settings.value(QString::fromUtf8("Preferences/General/SystrayEnabled"), true).toBool();
|
systrayIntegration = settings.value(QString::fromUtf8("Preferences/General/SystrayEnabled"), true).toBool();
|
||||||
|
systrayCreator = 0;
|
||||||
// Create tray icon
|
// Create tray icon
|
||||||
if (QSystemTrayIcon::isSystemTrayAvailable()) {
|
if (QSystemTrayIcon::isSystemTrayAvailable()) {
|
||||||
if(systrayIntegration) {
|
if(systrayIntegration) {
|
||||||
createTrayIcon();
|
createTrayIcon();
|
||||||
}
|
}
|
||||||
}else{
|
}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;
|
systrayIntegration = false;
|
||||||
qDebug("Info: System tray unavailable\n");
|
qDebug("Info: System tray unavailable");
|
||||||
}
|
}
|
||||||
// Setting icons
|
// Setting icons
|
||||||
this->setWindowIcon(QIcon(QString::fromUtf8(":/Icons/qbittorrent32.png")));
|
this->setWindowIcon(QIcon(QString::fromUtf8(":/Icons/qbittorrent32.png")));
|
||||||
@ -179,6 +186,9 @@ GUI::~GUI() {
|
|||||||
delete downloadingTorrentTab;
|
delete downloadingTorrentTab;
|
||||||
delete finishedTorrentTab;
|
delete finishedTorrentTab;
|
||||||
delete checkConnect;
|
delete checkConnect;
|
||||||
|
if(systrayCreator) {
|
||||||
|
delete systrayCreator;
|
||||||
|
}
|
||||||
if(systrayIntegration) {
|
if(systrayIntegration) {
|
||||||
delete myTrayIcon;
|
delete myTrayIcon;
|
||||||
delete myTrayIconMenu;
|
delete myTrayIconMenu;
|
||||||
@ -1262,6 +1272,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() {
|
void GUI::createTrayIcon() {
|
||||||
// Tray icon
|
// Tray icon
|
||||||
#ifdef Q_WS_WIN
|
#ifdef Q_WS_WIN
|
||||||
|
@ -59,6 +59,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
|||||||
QTabWidget *tabs;
|
QTabWidget *tabs;
|
||||||
options_imp *options;
|
options_imp *options;
|
||||||
QSystemTrayIcon *myTrayIcon;
|
QSystemTrayIcon *myTrayIcon;
|
||||||
|
QTimer *systrayCreator;
|
||||||
QMenu *myTrayIconMenu;
|
QMenu *myTrayIconMenu;
|
||||||
DownloadingTorrents *downloadingTorrentTab;
|
DownloadingTorrents *downloadingTorrentTab;
|
||||||
FinishedTorrents *finishedTorrentTab;
|
FinishedTorrents *finishedTorrentTab;
|
||||||
@ -106,6 +107,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{
|
|||||||
void updateFinishedTorrentNumber(unsigned int nb);
|
void updateFinishedTorrentNumber(unsigned int nb);
|
||||||
void fullDiskError(QTorrentHandle& h) const;
|
void fullDiskError(QTorrentHandle& h) const;
|
||||||
void handleDownloadFromUrlFailure(QString, QString) const;
|
void handleDownloadFromUrlFailure(QString, QString) const;
|
||||||
|
void createSystrayDelayed();
|
||||||
// Keyboard shortcuts
|
// Keyboard shortcuts
|
||||||
void createKeyboardShortcuts();
|
void createKeyboardShortcuts();
|
||||||
void displayDownTab() const;
|
void displayDownTab() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user