mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 05:13:30 -07:00
parent
670b381df7
commit
646322b2a2
3 changed files with 26 additions and 45 deletions
|
@ -85,7 +85,7 @@ DesktopIntegration::DesktopIntegration(QObject *parent)
|
||||||
MacUtils::overrideDockClickHandler(handleDockClicked);
|
MacUtils::overrideDockClickHandler(handleDockClicked);
|
||||||
#else
|
#else
|
||||||
if (Preferences::instance()->systemTrayEnabled())
|
if (Preferences::instance()->systemTrayEnabled())
|
||||||
createTrayIcon(20);
|
createTrayIcon();
|
||||||
|
|
||||||
#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS
|
#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS
|
||||||
if (isNotificationsEnabled())
|
if (isNotificationsEnabled())
|
||||||
|
@ -104,7 +104,7 @@ bool DesktopIntegration::isActive() const
|
||||||
#ifdef Q_OS_MACOS
|
#ifdef Q_OS_MACOS
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
return (m_systrayIcon != nullptr);
|
return QSystemTrayIcon::isSystemTrayAvailable();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,9 +118,10 @@ void DesktopIntegration::setToolTip(const QString &toolTip)
|
||||||
if (m_toolTip == toolTip)
|
if (m_toolTip == toolTip)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
m_toolTip = toolTip;
|
||||||
#ifndef Q_OS_MACOS
|
#ifndef Q_OS_MACOS
|
||||||
if (m_systrayIcon)
|
if (m_systrayIcon)
|
||||||
m_systrayIcon->setToolTip(toolTip);
|
m_systrayIcon->setToolTip(m_toolTip);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +217,7 @@ void DesktopIntegration::onPreferencesChanged()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
createTrayIcon(20);
|
createTrayIcon();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -229,45 +230,28 @@ void DesktopIntegration::onPreferencesChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef Q_OS_MACOS
|
#ifndef Q_OS_MACOS
|
||||||
void DesktopIntegration::createTrayIcon(const int retries)
|
void DesktopIntegration::createTrayIcon()
|
||||||
{
|
{
|
||||||
Q_ASSERT(!m_systrayIcon);
|
Q_ASSERT(!m_systrayIcon);
|
||||||
|
|
||||||
if (QSystemTrayIcon::isSystemTrayAvailable())
|
m_systrayIcon = new QSystemTrayIcon(UIThemeManager::instance()->getSystrayIcon(), this);
|
||||||
|
|
||||||
|
m_systrayIcon->setToolTip(m_toolTip);
|
||||||
|
|
||||||
|
if (m_menu)
|
||||||
|
m_systrayIcon->setContextMenu(m_menu);
|
||||||
|
|
||||||
|
connect(m_systrayIcon, &QSystemTrayIcon::activated, this
|
||||||
|
, [this](const QSystemTrayIcon::ActivationReason reason)
|
||||||
{
|
{
|
||||||
m_systrayIcon = new QSystemTrayIcon(UIThemeManager::instance()->getSystrayIcon(), this);
|
if (reason == QSystemTrayIcon::Trigger)
|
||||||
|
emit activationRequested();
|
||||||
m_systrayIcon->setToolTip(m_toolTip);
|
});
|
||||||
|
|
||||||
if (m_menu)
|
|
||||||
m_systrayIcon->setContextMenu(m_menu);
|
|
||||||
|
|
||||||
connect(m_systrayIcon, &QSystemTrayIcon::activated, this
|
|
||||||
, [this](const QSystemTrayIcon::ActivationReason reason)
|
|
||||||
{
|
|
||||||
if (reason == QSystemTrayIcon::Trigger)
|
|
||||||
emit activationRequested();
|
|
||||||
});
|
|
||||||
#ifndef QBT_USES_CUSTOMDBUSNOTIFICATIONS
|
#ifndef QBT_USES_CUSTOMDBUSNOTIFICATIONS
|
||||||
connect(m_systrayIcon, &QSystemTrayIcon::messageClicked, this, &DesktopIntegration::notificationClicked);
|
connect(m_systrayIcon, &QSystemTrayIcon::messageClicked, this, &DesktopIntegration::notificationClicked);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_systrayIcon->show();
|
m_systrayIcon->show();
|
||||||
emit stateChanged();
|
emit stateChanged();
|
||||||
}
|
|
||||||
else if (retries > 0)
|
|
||||||
{
|
|
||||||
LogMsg(tr("System tray icon is not available, retrying..."), Log::WARNING);
|
|
||||||
QTimer::singleShot(2s, this, [this, retries]()
|
|
||||||
{
|
|
||||||
if (Preferences::instance()->systemTrayEnabled())
|
|
||||||
createTrayIcon(retries - 1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogMsg(tr("System tray icon is still not available after retries. Disabling it."), Log::WARNING);
|
|
||||||
Preferences::instance()->setSystemTrayEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif // Q_OS_MACOS
|
#endif // Q_OS_MACOS
|
||||||
|
|
|
@ -76,7 +76,7 @@ signals:
|
||||||
private:
|
private:
|
||||||
void onPreferencesChanged();
|
void onPreferencesChanged();
|
||||||
#ifndef Q_OS_MACOS
|
#ifndef Q_OS_MACOS
|
||||||
void createTrayIcon(int retries);
|
void createTrayIcon();
|
||||||
#endif // Q_OS_MACOS
|
#endif // Q_OS_MACOS
|
||||||
|
|
||||||
CachedSettingValue<bool> m_storeNotificationEnabled;
|
CachedSettingValue<bool> m_storeNotificationEnabled;
|
||||||
|
|
|
@ -1507,13 +1507,10 @@ void MainWindow::reloadSessionStats()
|
||||||
MacUtils::setBadgeLabelText({});
|
MacUtils::setBadgeLabelText({});
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (app()->desktopIntegration()->isActive())
|
const auto toolTip = u"%1\n%2"_qs.arg(
|
||||||
{
|
tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true))
|
||||||
const auto toolTip = u"%1\n%2"_qs.arg(
|
, tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)));
|
||||||
tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true))
|
app()->desktopIntegration()->setToolTip(toolTip); // tray icon
|
||||||
, tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true)));
|
|
||||||
app()->desktopIntegration()->setToolTip(toolTip); // tray icon
|
|
||||||
}
|
|
||||||
#endif // Q_OS_MACOS
|
#endif // Q_OS_MACOS
|
||||||
|
|
||||||
if (m_displaySpeedInTitle)
|
if (m_displaySpeedInTitle)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue