|
|
|
@ -177,8 +177,14 @@ MainWindow::MainWindow(QWidget *parent)
@@ -177,8 +177,14 @@ MainWindow::MainWindow(QWidget *parent)
|
|
|
|
|
lockMenu->addAction(tr("&Set Password"), this, &MainWindow::defineUILockPassword); |
|
|
|
|
lockMenu->addAction(tr("&Clear Password"), this, &MainWindow::clearUILockPassword); |
|
|
|
|
m_ui->actionLock->setMenu(lockMenu); |
|
|
|
|
connect(this, &MainWindow::systemTrayIconCreated, this, [this]() |
|
|
|
|
{ |
|
|
|
|
m_ui->actionLock->setVisible(true); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Creating Bittorrent session
|
|
|
|
|
updateAltSpeedsBtn(BitTorrent::Session::instance()->isAltGlobalSpeedLimitEnabled()); |
|
|
|
|
|
|
|
|
|
connect(BitTorrent::Session::instance(), &BitTorrent::Session::fullDiskError, this, &MainWindow::fullDiskError); |
|
|
|
|
connect(BitTorrent::Session::instance(), &BitTorrent::Session::loadTorrentFailed, this, &MainWindow::addTorrentFailed); |
|
|
|
|
connect(BitTorrent::Session::instance(), &BitTorrent::Session::torrentAdded,this, &MainWindow::torrentNew); |
|
|
|
@ -319,7 +325,7 @@ MainWindow::MainWindow(QWidget *parent)
@@ -319,7 +325,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|
|
|
|
connect(m_preventTimer, &QTimer::timeout, this, &MainWindow::updatePowerManagementState); |
|
|
|
|
|
|
|
|
|
// Configure BT session according to options
|
|
|
|
|
loadPreferences(false); |
|
|
|
|
loadPreferences(); |
|
|
|
|
|
|
|
|
|
connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated, this, &MainWindow::reloadSessionStats); |
|
|
|
|
connect(BitTorrent::Session::instance(), &BitTorrent::Session::torrentsUpdated, this, &MainWindow::reloadTorrentStats); |
|
|
|
@ -380,7 +386,19 @@ MainWindow::MainWindow(QWidget *parent)
@@ -380,7 +386,19 @@ MainWindow::MainWindow(QWidget *parent)
|
|
|
|
|
// Load Window state and sizes
|
|
|
|
|
readSettings(); |
|
|
|
|
|
|
|
|
|
#ifndef Q_OS_MACOS |
|
|
|
|
#ifdef Q_OS_MACOS |
|
|
|
|
// Make sure the Window is visible if we don't have a tray icon
|
|
|
|
|
if (pref->startMinimized()) |
|
|
|
|
{ |
|
|
|
|
showMinimized(); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
show(); |
|
|
|
|
activateWindow(); |
|
|
|
|
raise(); |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
if (m_systrayIcon) |
|
|
|
|
{ |
|
|
|
|
if (!(pref->startMinimized() || m_uiLocked)) |
|
|
|
@ -405,7 +423,6 @@ MainWindow::MainWindow(QWidget *parent)
@@ -405,7 +423,6 @@ MainWindow::MainWindow(QWidget *parent)
|
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
#endif |
|
|
|
|
// Make sure the Window is visible if we don't have a tray icon
|
|
|
|
|
if (pref->startMinimized()) |
|
|
|
|
{ |
|
|
|
@ -417,7 +434,6 @@ MainWindow::MainWindow(QWidget *parent)
@@ -417,7 +434,6 @@ MainWindow::MainWindow(QWidget *parent)
|
|
|
|
|
activateWindow(); |
|
|
|
|
raise(); |
|
|
|
|
} |
|
|
|
|
#ifndef Q_OS_MACOS |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
@ -456,7 +472,8 @@ MainWindow::MainWindow(QWidget *parent)
@@ -456,7 +472,8 @@ MainWindow::MainWindow(QWidget *parent)
|
|
|
|
|
#endif |
|
|
|
|
#ifdef Q_OS_MACOS |
|
|
|
|
setupDockClickHandler(); |
|
|
|
|
trayIconMenu()->setAsDockMenu(); |
|
|
|
|
createTrayIconMenu(); |
|
|
|
|
m_trayIconMenu->setAsDockMenu(); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -785,10 +802,6 @@ void MainWindow::cleanup()
@@ -785,10 +802,6 @@ void MainWindow::cleanup()
|
|
|
|
|
delete m_rssWidget; |
|
|
|
|
|
|
|
|
|
delete m_executableWatcher; |
|
|
|
|
#ifndef Q_OS_MACOS |
|
|
|
|
if (m_systrayCreator) |
|
|
|
|
m_systrayCreator->stop(); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
m_preventTimer->stop(); |
|
|
|
|
|
|
|
|
@ -1218,15 +1231,15 @@ void MainWindow::closeEvent(QCloseEvent *e)
@@ -1218,15 +1231,15 @@ void MainWindow::closeEvent(QCloseEvent *e)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// abort search if any
|
|
|
|
|
delete m_searchWidget; |
|
|
|
|
|
|
|
|
|
hide(); |
|
|
|
|
// Disable some UI to prevent user interactions
|
|
|
|
|
#ifndef Q_OS_MACOS |
|
|
|
|
// Hide tray icon
|
|
|
|
|
if (m_systrayIcon) |
|
|
|
|
m_systrayIcon->hide(); |
|
|
|
|
{ |
|
|
|
|
m_systrayIcon->setToolTip(tr("qBittorrent is shutting down...")); |
|
|
|
|
m_trayIconMenu->setEnabled(false); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// Accept exit
|
|
|
|
|
e->accept(); |
|
|
|
|
qApp->exit(); |
|
|
|
@ -1469,50 +1482,32 @@ void MainWindow::showStatusBar(bool show)
@@ -1469,50 +1482,32 @@ void MainWindow::showStatusBar(bool show)
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MainWindow::loadPreferences(const bool configureSession) |
|
|
|
|
{ |
|
|
|
|
const Preferences *const pref = Preferences::instance(); |
|
|
|
|
#ifdef Q_OS_MACOS |
|
|
|
|
Q_UNUSED(configureSession); |
|
|
|
|
#else |
|
|
|
|
const bool newSystrayIntegration = pref->systrayIntegration(); |
|
|
|
|
m_ui->actionLock->setVisible(newSystrayIntegration); |
|
|
|
|
if (newSystrayIntegration != (m_systrayIcon != nullptr)) |
|
|
|
|
void MainWindow::loadPreferences() |
|
|
|
|
{ |
|
|
|
|
if (newSystrayIntegration) |
|
|
|
|
{ |
|
|
|
|
// create the trayicon
|
|
|
|
|
if (!QSystemTrayIcon::isSystemTrayAvailable()) |
|
|
|
|
const Preferences *pref = Preferences::instance(); |
|
|
|
|
|
|
|
|
|
#ifndef Q_OS_MACOS |
|
|
|
|
// system tray icon
|
|
|
|
|
if (pref->systemTrayEnabled()) |
|
|
|
|
{ |
|
|
|
|
if (!configureSession) |
|
|
|
|
{ // Program startup
|
|
|
|
|
m_systrayCreator = new QTimer(this); |
|
|
|
|
connect(m_systrayCreator.data(), &QTimer::timeout, this, &MainWindow::createSystrayDelayed); |
|
|
|
|
m_systrayCreator->setSingleShot(true); |
|
|
|
|
m_systrayCreator->start(2000); |
|
|
|
|
qDebug("Info: System tray is unavailable, trying again later."); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
if (m_systrayIcon) |
|
|
|
|
{ |
|
|
|
|
qDebug("Warning: System tray is unavailable."); |
|
|
|
|
} |
|
|
|
|
// Reload systray icon
|
|
|
|
|
m_systrayIcon->setIcon(UIThemeManager::instance()->getSystrayIcon()); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
createTrayIcon(); |
|
|
|
|
createTrayIcon(20); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
// Destroy trayicon
|
|
|
|
|
delete m_systrayIcon; |
|
|
|
|
delete m_trayIconMenu; |
|
|
|
|
m_ui->actionLock->setVisible(false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Reload systray icon
|
|
|
|
|
if (newSystrayIntegration && m_systrayIcon) |
|
|
|
|
m_systrayIcon->setIcon(getSystrayIcon()); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// General
|
|
|
|
|
if (pref->isToolbarDisplayed()) |
|
|
|
|
{ |
|
|
|
@ -1621,7 +1616,7 @@ void MainWindow::reloadSessionStats()
@@ -1621,7 +1616,7 @@ void MainWindow::reloadSessionStats()
|
|
|
|
|
#else |
|
|
|
|
if (m_systrayIcon) |
|
|
|
|
{ |
|
|
|
|
const QString toolTip = QString::fromLatin1("%1\n%2").arg( |
|
|
|
|
const auto toolTip = QString::fromLatin1("%1\n%2").arg( |
|
|
|
|
tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true)) |
|
|
|
|
, tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true))); |
|
|
|
|
m_systrayIcon->setToolTip(toolTip); // tray icon
|
|
|
|
@ -1705,86 +1700,82 @@ void MainWindow::downloadFromURLList(const QStringList &urlList)
@@ -1705,86 +1700,82 @@ void MainWindow::downloadFromURLList(const QStringList &urlList)
|
|
|
|
|
*****************************************************/ |
|
|
|
|
|
|
|
|
|
#ifndef Q_OS_MACOS |
|
|
|
|
void MainWindow::createSystrayDelayed() |
|
|
|
|
void MainWindow::createTrayIcon(const int retries) |
|
|
|
|
{ |
|
|
|
|
static int timeout = 20; |
|
|
|
|
if (m_systrayIcon) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (QSystemTrayIcon::isSystemTrayAvailable()) |
|
|
|
|
{ |
|
|
|
|
// Ok, systray integration is now supported
|
|
|
|
|
// Create systray icon
|
|
|
|
|
createTrayIcon(); |
|
|
|
|
delete m_systrayCreator; |
|
|
|
|
m_systrayIcon = new QSystemTrayIcon(UIThemeManager::instance()->getSystrayIcon(), this); |
|
|
|
|
|
|
|
|
|
createTrayIconMenu(); |
|
|
|
|
m_systrayIcon->setContextMenu(m_trayIconMenu); |
|
|
|
|
|
|
|
|
|
connect(m_systrayIcon, &QSystemTrayIcon::activated, this, &MainWindow::toggleVisibility); |
|
|
|
|
connect(m_systrayIcon, &QSystemTrayIcon::messageClicked, this, &MainWindow::balloonClicked); |
|
|
|
|
|
|
|
|
|
m_systrayIcon->show(); |
|
|
|
|
emit systemTrayIconCreated(); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
if (timeout) |
|
|
|
|
if (retries > 0) |
|
|
|
|
{ |
|
|
|
|
LogMsg("System tray icon is not available, retrying...", Log::WARNING); |
|
|
|
|
QTimer::singleShot(std::chrono::seconds(2), this, [this, retries]() |
|
|
|
|
{ |
|
|
|
|
// Retry a bit later
|
|
|
|
|
m_systrayCreator->start(2000); |
|
|
|
|
--timeout; |
|
|
|
|
if (Preferences::instance()->systemTrayEnabled()) |
|
|
|
|
createTrayIcon(retries - 1); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
// Timed out, apparently system really does not
|
|
|
|
|
// support systray icon
|
|
|
|
|
delete m_systrayCreator; |
|
|
|
|
// Disable it in program preferences to
|
|
|
|
|
// avoid trying at each startup
|
|
|
|
|
Preferences::instance()->setSystrayIntegration(false); |
|
|
|
|
} |
|
|
|
|
LogMsg("System tray icon is still not available after retries. Disabling it.", Log::WARNING); |
|
|
|
|
Preferences::instance()->setSystemTrayEnabled(false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MainWindow::updateTrayIconMenu() |
|
|
|
|
{ |
|
|
|
|
m_ui->actionToggleVisibility->setText(isVisible() ? tr("Hide") : tr("Show")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MainWindow::createTrayIcon() |
|
|
|
|
{ |
|
|
|
|
// Tray icon
|
|
|
|
|
m_systrayIcon = new QSystemTrayIcon(getSystrayIcon(), this); |
|
|
|
|
|
|
|
|
|
m_systrayIcon->setContextMenu(trayIconMenu()); |
|
|
|
|
connect(m_systrayIcon.data(), &QSystemTrayIcon::messageClicked, this, &MainWindow::balloonClicked); |
|
|
|
|
// End of Icon Menu
|
|
|
|
|
connect(m_systrayIcon.data(), &QSystemTrayIcon::activated, this, &MainWindow::toggleVisibility); |
|
|
|
|
m_systrayIcon->show(); |
|
|
|
|
} |
|
|
|
|
#endif // Q_OS_MACOS
|
|
|
|
|
|
|
|
|
|
QMenu *MainWindow::trayIconMenu() |
|
|
|
|
void MainWindow::createTrayIconMenu() |
|
|
|
|
{ |
|
|
|
|
if (m_trayIconMenu) return m_trayIconMenu; |
|
|
|
|
if (m_trayIconMenu) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
m_trayIconMenu = new QMenu(this); |
|
|
|
|
|
|
|
|
|
#ifndef Q_OS_MACOS |
|
|
|
|
connect(m_trayIconMenu.data(), &QMenu::aboutToShow, this, &MainWindow::updateTrayIconMenu); |
|
|
|
|
connect(m_trayIconMenu, &QMenu::aboutToShow, this, [this]() |
|
|
|
|
{ |
|
|
|
|
m_ui->actionToggleVisibility->setText(isVisible() ? tr("Hide") : tr("Show")); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
m_trayIconMenu->addAction(m_ui->actionToggleVisibility); |
|
|
|
|
m_trayIconMenu->addSeparator(); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
m_trayIconMenu->addAction(m_ui->actionOpen); |
|
|
|
|
m_trayIconMenu->addAction(m_ui->actionDownloadFromURL); |
|
|
|
|
m_trayIconMenu->addSeparator(); |
|
|
|
|
const bool isAltBWEnabled = BitTorrent::Session::instance()->isAltGlobalSpeedLimitEnabled(); |
|
|
|
|
updateAltSpeedsBtn(isAltBWEnabled); |
|
|
|
|
m_ui->actionUseAlternativeSpeedLimits->setChecked(isAltBWEnabled); |
|
|
|
|
|
|
|
|
|
m_trayIconMenu->addAction(m_ui->actionUseAlternativeSpeedLimits); |
|
|
|
|
m_trayIconMenu->addAction(m_ui->actionSetGlobalSpeedLimits); |
|
|
|
|
m_trayIconMenu->addSeparator(); |
|
|
|
|
|
|
|
|
|
m_trayIconMenu->addAction(m_ui->actionStartAll); |
|
|
|
|
m_trayIconMenu->addAction(m_ui->actionPauseAll); |
|
|
|
|
|
|
|
|
|
#ifndef Q_OS_MACOS |
|
|
|
|
m_trayIconMenu->addSeparator(); |
|
|
|
|
m_trayIconMenu->addAction(m_ui->actionExit); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
if (m_uiLocked) |
|
|
|
|
m_trayIconMenu->setEnabled(false); |
|
|
|
|
|
|
|
|
|
return m_trayIconMenu; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void MainWindow::updateAltSpeedsBtn(bool alternative) |
|
|
|
|
void MainWindow::updateAltSpeedsBtn(const bool alternative) |
|
|
|
|
{ |
|
|
|
|
m_ui->actionUseAlternativeSpeedLimits->setChecked(alternative); |
|
|
|
|
} |
|
|
|
@ -2072,42 +2063,6 @@ void MainWindow::updatePowerManagementState()
@@ -2072,42 +2063,6 @@ void MainWindow::updatePowerManagementState()
|
|
|
|
|
m_pwr->setActivityState(inhibitSuspend); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifndef Q_OS_MACOS |
|
|
|
|
QIcon MainWindow::getSystrayIcon() const |
|
|
|
|
{ |
|
|
|
|
const TrayIcon::Style style = Preferences::instance()->trayIconStyle(); |
|
|
|
|
// on Linux we use theme icons, and icons from resources everywhere else
|
|
|
|
|
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) |
|
|
|
|
switch (style) |
|
|
|
|
{ |
|
|
|
|
case TrayIcon::Style::Normal: |
|
|
|
|
return QIcon::fromTheme(QLatin1String("qbittorrent-tray")); |
|
|
|
|
case TrayIcon::Style::MonoDark: |
|
|
|
|
return QIcon::fromTheme(QLatin1String("qbittorrent-tray-dark")); |
|
|
|
|
case TrayIcon::Style::MonoLight: |
|
|
|
|
return QIcon::fromTheme(QLatin1String("qbittorrent-tray-light")); |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
switch (style) |
|
|
|
|
{ |
|
|
|
|
case TrayIcon::Style::Normal: |
|
|
|
|
return UIThemeManager::instance()->getIcon(QLatin1String("qbittorrent-tray")); |
|
|
|
|
case TrayIcon::Style::MonoDark: |
|
|
|
|
return UIThemeManager::instance()->getIcon(QLatin1String("qbittorrent-tray-dark")); |
|
|
|
|
case TrayIcon::Style::MonoLight: |
|
|
|
|
return UIThemeManager::instance()->getIcon(QLatin1String("qbittorrent-tray-light")); |
|
|
|
|
default: |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// As a failsafe in case the enum is invalid
|
|
|
|
|
return UIThemeManager::instance()->getIcon(QLatin1String("qbittorrent-tray")); |
|
|
|
|
} |
|
|
|
|
#endif // Q_OS_MACOS
|
|
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) |
|
|
|
|
void MainWindow::checkProgramUpdate(const bool invokedByUser) |
|
|
|
|
{ |
|
|
|
|