mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-31 20:58:07 -06:00
Revamp system tray icon menu handling
Update system tray icon menu without re-create it. PR #20597. Closes #20516.
This commit is contained in:
committed by
GitHub
parent
489bacd766
commit
5e8b9df859
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2022 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2022-2024 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@@ -73,6 +73,7 @@ using namespace std::chrono_literals;
|
||||
DesktopIntegration::DesktopIntegration(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_storeNotificationEnabled {NOTIFICATIONS_SETTINGS_KEY(u"Enabled"_s), true}
|
||||
, m_menu {new QMenu}
|
||||
#ifdef QBT_USES_DBUS
|
||||
, m_storeNotificationTimeOut {NOTIFICATIONS_SETTINGS_KEY(u"Timeout"_s), -1}
|
||||
#endif
|
||||
@@ -80,6 +81,7 @@ DesktopIntegration::DesktopIntegration(QObject *parent)
|
||||
#ifdef Q_OS_MACOS
|
||||
desktopIntegrationInstance = this;
|
||||
MacUtils::overrideDockClickHandler(handleDockClicked);
|
||||
m_menu->setAsDockMenu();
|
||||
#else
|
||||
if (Preferences::instance()->systemTrayEnabled())
|
||||
createTrayIcon();
|
||||
@@ -132,46 +134,6 @@ QMenu *DesktopIntegration::menu() const
|
||||
return m_menu;
|
||||
}
|
||||
|
||||
void DesktopIntegration::setMenu(QMenu *menu)
|
||||
{
|
||||
if (menu == m_menu)
|
||||
return;
|
||||
|
||||
#if defined Q_OS_MACOS
|
||||
if (m_menu)
|
||||
delete m_menu;
|
||||
|
||||
m_menu = menu;
|
||||
|
||||
if (m_menu)
|
||||
m_menu->setAsDockMenu();
|
||||
#elif defined Q_OS_UNIX
|
||||
const bool systemTrayEnabled = m_systrayIcon;
|
||||
if (m_menu)
|
||||
{
|
||||
if (m_systrayIcon)
|
||||
{
|
||||
delete m_systrayIcon;
|
||||
m_systrayIcon = nullptr;
|
||||
}
|
||||
delete m_menu;
|
||||
}
|
||||
|
||||
m_menu = menu;
|
||||
|
||||
if (systemTrayEnabled && !m_systrayIcon)
|
||||
createTrayIcon();
|
||||
#else
|
||||
if (m_menu)
|
||||
delete m_menu;
|
||||
|
||||
m_menu = menu;
|
||||
|
||||
if (m_systrayIcon)
|
||||
m_systrayIcon->setContextMenu(m_menu);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool DesktopIntegration::isNotificationsEnabled() const
|
||||
{
|
||||
return m_storeNotificationEnabled;
|
||||
|
||||
Reference in New Issue
Block a user