diff --git a/src/app/application.cpp b/src/app/application.cpp index 4fb84e734..feaf2d245 100644 --- a/src/app/application.cpp +++ b/src/app/application.cpp @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2015 Vladimir Golovnev + * Copyright (C) 2015-2024 Vladimir Golovnev * Copyright (C) 2006 Christophe Dumez * * This program is free software; you can redistribute it and/or @@ -832,7 +832,7 @@ int Application::exec() m_desktopIntegration = new DesktopIntegration; m_desktopIntegration->setToolTip(tr("Loading torrents...")); #ifndef Q_OS_MACOS - auto *desktopIntegrationMenu = new QMenu; + auto *desktopIntegrationMenu = m_desktopIntegration->menu(); auto *actionExit = new QAction(tr("E&xit"), desktopIntegrationMenu); actionExit->setIcon(UIThemeManager::instance()->getIcon(u"application-exit"_s)); actionExit->setMenuRole(QAction::QuitRole); @@ -843,8 +843,6 @@ int Application::exec() }); desktopIntegrationMenu->addAction(actionExit); - m_desktopIntegration->setMenu(desktopIntegrationMenu); - const bool isHidden = m_desktopIntegration->isActive() && (startUpWindowState() == WindowState::Hidden); #else const bool isHidden = false; diff --git a/src/gui/desktopintegration.cpp b/src/gui/desktopintegration.cpp index 2416f8134..b927633d9 100644 --- a/src/gui/desktopintegration.cpp +++ b/src/gui/desktopintegration.cpp @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2022 Vladimir Golovnev + * Copyright (C) 2022-2024 Vladimir Golovnev * Copyright (C) 2006 Christophe Dumez * * 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; diff --git a/src/gui/desktopintegration.h b/src/gui/desktopintegration.h index 62dbbc4a9..c4b9aba49 100644 --- a/src/gui/desktopintegration.h +++ b/src/gui/desktopintegration.h @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2022 Vladimir Golovnev + * Copyright (C) 2022-2024 Vladimir Golovnev * Copyright (C) 2006 Christophe Dumez * * This program is free software; you can redistribute it and/or @@ -56,7 +56,6 @@ public: void setToolTip(const QString &toolTip); QMenu *menu() const; - void setMenu(QMenu *menu); bool isNotificationsEnabled() const; void setNotificationsEnabled(bool value); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 8058957e4..4040682f8 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2022-2023 Vladimir Golovnev + * Copyright (C) 2022-2024 Vladimir Golovnev * Copyright (C) 2006 Christophe Dumez * * This program is free software; you can redistribute it and/or @@ -293,9 +293,6 @@ MainWindow::MainWindow(IGUIApplication *app, const WindowState initialState, con connect(m_ui->actionIncreaseQueuePos, &QAction::triggered, m_transferListWidget, &TransferListWidget::increaseQueuePosSelectedTorrents); connect(m_ui->actionDecreaseQueuePos, &QAction::triggered, m_transferListWidget, &TransferListWidget::decreaseQueuePosSelectedTorrents); connect(m_ui->actionBottomQueuePos, &QAction::triggered, m_transferListWidget, &TransferListWidget::bottomQueuePosSelectedTorrents); -#ifndef Q_OS_MACOS - connect(m_ui->actionToggleVisibility, &QAction::triggered, this, &MainWindow::toggleVisibility); -#endif connect(m_ui->actionMinimize, &QAction::triggered, this, &MainWindow::minimizeWindow); connect(m_ui->actionUseAlternativeSpeedLimits, &QAction::triggered, this, &MainWindow::toggleAlternativeSpeeds); @@ -387,7 +384,7 @@ MainWindow::MainWindow(IGUIApplication *app, const WindowState initialState, con // Load Window state and sizes loadSettings(); - app->desktopIntegration()->setMenu(createDesktopIntegrationMenu()); + populateDesktopIntegrationMenu(); #ifndef Q_OS_MACOS m_ui->actionLock->setVisible(app->desktopIntegration()->isActive()); connect(app->desktopIntegration(), &DesktopIntegration::stateChanged, this, [this, app]() @@ -1326,12 +1323,6 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event) event->acceptProposedAction(); } -/***************************************************** -* * -* Torrent * -* * -*****************************************************/ - // Display a dialog to allow user to add // torrents to download list void MainWindow::on_actionOpen_triggered() @@ -1527,33 +1518,23 @@ void MainWindow::reloadTorrentStats(const QVector &torren } } -/***************************************************** -* * -* Utils * -* * -*****************************************************/ - void MainWindow::downloadFromURLList(const QStringList &urlList) { for (const QString &url : urlList) app()->addTorrentManager()->addTorrent(url); } -/***************************************************** -* * -* Options * -* * -*****************************************************/ - -QMenu *MainWindow::createDesktopIntegrationMenu() +void MainWindow::populateDesktopIntegrationMenu() { - auto *menu = new QMenu; + auto *menu = app()->desktopIntegration()->menu(); + menu->clear(); #ifndef Q_OS_MACOS connect(menu, &QMenu::aboutToShow, this, [this]() { m_ui->actionToggleVisibility->setText(isVisible() ? tr("Hide") : tr("Show")); }); + connect(m_ui->actionToggleVisibility, &QAction::triggered, this, &MainWindow::toggleVisibility); menu->addAction(m_ui->actionToggleVisibility); menu->addSeparator(); @@ -1577,8 +1558,6 @@ QMenu *MainWindow::createDesktopIntegrationMenu() if (m_uiLocked) menu->setEnabled(false); - - return menu; } void MainWindow::updateAltSpeedsBtn(const bool alternative) @@ -1696,12 +1675,6 @@ void MainWindow::on_actionSearchWidget_triggered() displaySearchTab(m_ui->actionSearchWidget->isChecked()); } -/***************************************************** -* * -* HTTP Downloader * -* * -*****************************************************/ - // Display an input dialog to prompt user for // an url void MainWindow::on_actionDownloadFromURL_triggered() diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 383d9ac14..1f03f3225 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2022 Vladimir Golovnev + * Copyright (C) 2022-2024 Vladimir Golovnev * Copyright (C) 2006 Christophe Dumez * * This program is free software; you can redistribute it and/or @@ -186,7 +186,7 @@ private slots: #endif private: - QMenu *createDesktopIntegrationMenu(); + void populateDesktopIntegrationMenu(); #ifdef Q_OS_WIN void installPython(); #endif