From 5dcc14153f046209f1067299494a82e5294d883a Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 10 Apr 2023 13:38:00 +0800 Subject: [PATCH] Move feature macro declaration to build scripts PR #18825. --- cmake/Modules/CommonConfig.cmake | 4 ++++ configure | 2 +- configure.ac | 2 +- src/base/utils/misc.cpp | 4 ++-- src/gui/advancedsettings.cpp | 9 +++++---- src/gui/advancedsettings.h | 5 ++--- src/gui/desktopintegration.cpp | 16 ++++++++-------- src/gui/desktopintegration.h | 7 +++---- src/gui/mainwindow.cpp | 2 +- src/gui/optionsdialog.cpp | 2 +- src/gui/powermanagement/powermanagement.cpp | 8 ++++---- src/gui/powermanagement/powermanagement.h | 4 ++-- 12 files changed, 34 insertions(+), 31 deletions(-) diff --git a/cmake/Modules/CommonConfig.cmake b/cmake/Modules/CommonConfig.cmake index 8e7a4c074..57072e594 100644 --- a/cmake/Modules/CommonConfig.cmake +++ b/cmake/Modules/CommonConfig.cmake @@ -101,6 +101,10 @@ if (MSVC) endif() endif() +if (DBUS) + target_compile_definitions(qbt_common_cfg INTERFACE QBT_USES_DBUS) +endif() + if (LibtorrentRasterbar_VERSION VERSION_GREATER_EQUAL ${minLibtorrentVersion}) target_compile_definitions(qbt_common_cfg INTERFACE QBT_USES_LIBTORRENT2) endif() diff --git a/configure b/configure index 5cbe6cca5..9d2a53e98 100755 --- a/configure +++ b/configure @@ -5649,7 +5649,7 @@ fi then : as_fn_error $? "Could not find QtDBus" "$LINENO" 5 else $as_nop - QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus" + QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus" QBT_ADD_DEFINES="$QBT_ADD_DEFINES QBT_USES_DBUS" fi ;; #( "xno") : diff --git a/configure.ac b/configure.ac index b1c3ebbb7..ff62dc15c 100644 --- a/configure.ac +++ b/configure.ac @@ -165,7 +165,7 @@ AS_CASE(["x$enable_qt_dbus"], FIND_QTDBUS() AS_IF([test "x$HAVE_QTDBUS" = "xfalse"], [AC_MSG_ERROR([Could not find QtDBus])], - [QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus"] + [QBT_ADD_CONFIG="$QBT_ADD_CONFIG dbus" QBT_ADD_DEFINES="$QBT_ADD_DEFINES QBT_USES_DBUS"] )], ["xno"], [AC_MSG_RESULT([no]) diff --git a/src/base/utils/misc.cpp b/src/base/utils/misc.cpp index e9803f36c..7d6d84c64 100644 --- a/src/base/utils/misc.cpp +++ b/src/base/utils/misc.cpp @@ -61,7 +61,7 @@ #include #include -#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) +#ifdef QBT_USES_DBUS #include #endif @@ -188,7 +188,7 @@ void Utils::Misc::shutdownComputer(const ShutdownDialogAction &action) AEDisposeDesc(&eventReply); -#elif (defined(Q_OS_UNIX) && defined(QT_DBUS_LIB)) +#elif defined(QBT_USES_DBUS) // Use dbus to power off / suspend the system if (action != ShutdownDialogAction::Shutdown) { diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 2ad64667f..e9d6ca2ae 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -40,6 +40,7 @@ #include "base/preferences.h" #include "base/unicodestrings.h" #include "gui/addnewtorrentdialog.h" +#include "gui/desktopintegration.h" #include "gui/mainwindow.h" #include "interfaces/iguiapplication.h" @@ -82,7 +83,7 @@ namespace RESOLVE_COUNTRIES, PROGRAM_NOTIFICATIONS, TORRENT_ADDED_NOTIFICATIONS, -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS NOTIFICATION_TIMEOUT, #endif CONFIRM_REMOVE_ALL_TAGS, @@ -282,7 +283,7 @@ void AdvancedSettings::saveAdvancedSettings() const session->setStopTrackerTimeout(m_spinBoxStopTrackerTimeout.value()); // Program notification app()->desktopIntegration()->setNotificationsEnabled(m_checkBoxProgramNotifications.isChecked()); -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS app()->desktopIntegration()->setNotificationTimeout(m_spinBoxNotificationTimeout.value()); #endif app()->setTorrentAddedNotificationsEnabled(m_checkBoxTorrentAddedNotifications.isChecked()); @@ -332,7 +333,7 @@ void AdvancedSettings::updateCacheSpinSuffix(const int value) } #endif -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS void AdvancedSettings::updateNotificationTimeoutSuffix(const int value) { if (value == 0) @@ -728,7 +729,7 @@ void AdvancedSettings::loadAdvancedSettings() // Torrent added notifications m_checkBoxTorrentAddedNotifications.setChecked(app()->isTorrentAddedNotificationsEnabled()); addRow(TORRENT_ADDED_NOTIFICATIONS, tr("Display notifications for added torrents"), &m_checkBoxTorrentAddedNotifications); -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS // Notification timeout m_spinBoxNotificationTimeout.setMinimum(-1); m_spinBoxNotificationTimeout.setMaximum(std::numeric_limits::max()); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 5b0ab9b70..ab7f84800 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -34,7 +34,6 @@ #include #include -#include "gui/desktopintegration.h" #include "guiapplicationcomponent.h" class AdvancedSettings final : public QTableWidget, public GUIApplicationComponent @@ -58,7 +57,7 @@ private slots: void updateCacheSpinSuffix(int value); #endif -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS void updateNotificationTimeoutSuffix(int value); #endif @@ -98,7 +97,7 @@ private: QCheckBox m_checkBoxIconsInMenusEnabled; #endif -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS QSpinBox m_spinBoxNotificationTimeout; #endif }; diff --git a/src/gui/desktopintegration.cpp b/src/gui/desktopintegration.cpp index 5ef14e726..825d8cb99 100644 --- a/src/gui/desktopintegration.cpp +++ b/src/gui/desktopintegration.cpp @@ -45,7 +45,7 @@ #include "macutilities.h" #endif -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS #include "notifications/dbusnotifier.h" #endif @@ -75,7 +75,7 @@ using namespace std::chrono_literals; DesktopIntegration::DesktopIntegration(QObject *parent) : QObject(parent) , m_storeNotificationEnabled {NOTIFICATIONS_SETTINGS_KEY(u"Enabled"_qs), true} -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS , m_storeNotificationTimeOut {NOTIFICATIONS_SETTINGS_KEY(u"Timeout"_qs), -1} #endif { @@ -86,7 +86,7 @@ DesktopIntegration::DesktopIntegration(QObject *parent) if (Preferences::instance()->systemTrayEnabled()) createTrayIcon(); -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS if (isNotificationsEnabled()) { m_notifier = new DBusNotifier(this); @@ -187,7 +187,7 @@ void DesktopIntegration::setNotificationsEnabled(const bool value) m_storeNotificationEnabled = value; -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS if (value) { m_notifier = new DBusNotifier(this); @@ -203,14 +203,14 @@ void DesktopIntegration::setNotificationsEnabled(const bool value) int DesktopIntegration::notificationTimeout() const { -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS return m_storeNotificationTimeOut; #else return 5000; #endif } -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS void DesktopIntegration::setNotificationTimeout(const int value) { m_storeNotificationTimeOut = value; @@ -225,7 +225,7 @@ void DesktopIntegration::showNotification(const QString &title, const QString &m #ifdef Q_OS_MACOS MacUtils::displayNotification(title, msg); #else -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS m_notifier->showMessage(title, msg, notificationTimeout()); #else if (m_systrayIcon && QSystemTrayIcon::supportsMessages()) @@ -276,7 +276,7 @@ void DesktopIntegration::createTrayIcon() if (reason == QSystemTrayIcon::Trigger) emit activationRequested(); }); -#ifndef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifndef QBT_USES_DBUS connect(m_systrayIcon, &QSystemTrayIcon::messageClicked, this, &DesktopIntegration::notificationClicked); #endif diff --git a/src/gui/desktopintegration.h b/src/gui/desktopintegration.h index a965077df..3d55262e7 100644 --- a/src/gui/desktopintegration.h +++ b/src/gui/desktopintegration.h @@ -37,8 +37,7 @@ class QMenu; #ifndef Q_OS_MACOS class QSystemTrayIcon; #endif -#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) -#define QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS class DBusNotifier; #endif @@ -63,7 +62,7 @@ public: void setNotificationsEnabled(bool value); int notificationTimeout() const; -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS void setNotificationTimeout(const int value); #endif @@ -88,7 +87,7 @@ private: #ifndef Q_OS_MACOS QSystemTrayIcon *m_systrayIcon = nullptr; #endif -#ifdef QBT_USES_CUSTOMDBUSNOTIFICATIONS +#ifdef QBT_USES_DBUS CachedSettingValue m_storeNotificationTimeOut; DBusNotifier *m_notifier = nullptr; #endif diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index d9e7dab1c..f2e793c8f 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -359,7 +359,7 @@ MainWindow::MainWindow(IGUIApplication *app, WindowState initialState) autoShutdownGroup->addAction(m_ui->actionAutoShutdown); autoShutdownGroup->addAction(m_ui->actionAutoSuspend); autoShutdownGroup->addAction(m_ui->actionAutoHibernate); -#if (!defined(Q_OS_UNIX) || defined(Q_OS_MACOS)) || defined(QT_DBUS_LIB) +#if (!defined(Q_OS_UNIX) || defined(Q_OS_MACOS)) || defined(QBT_USES_DBUS) m_ui->actionAutoShutdown->setChecked(pref->shutdownWhenDownloadsComplete()); m_ui->actionAutoSuspend->setChecked(pref->suspendWhenDownloadsComplete()); m_ui->actionAutoHibernate->setChecked(pref->hibernateWhenDownloadsComplete()); diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index 78a7490c5..d94f65486 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -369,7 +369,7 @@ void OptionsDialog::loadBehaviorTabOptions() connect(m_ui->checkProgramUpdates, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); #endif -#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && !defined(QT_DBUS_LIB) +#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && !defined(QBT_USES_DBUS) m_ui->checkPreventFromSuspendWhenDownloading->setDisabled(true); m_ui->checkPreventFromSuspendWhenSeeding->setDisabled(true); #endif diff --git a/src/gui/powermanagement/powermanagement.cpp b/src/gui/powermanagement/powermanagement.cpp index 4c43584b9..174548cf8 100644 --- a/src/gui/powermanagement/powermanagement.cpp +++ b/src/gui/powermanagement/powermanagement.cpp @@ -38,14 +38,14 @@ #include #endif -#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) +#ifdef QBT_USES_DBUS #include "powermanagement_x11.h" #endif PowerManagement::PowerManagement(QObject *parent) : QObject(parent) { -#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) +#ifdef QBT_USES_DBUS m_inhibitor = new PowerManagementInhibitor(this); #endif } @@ -69,7 +69,7 @@ void PowerManagement::setBusy() #ifdef Q_OS_WIN SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED); -#elif (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) +#elif defined(QBT_USES_DBUS) m_inhibitor->requestBusy(); #elif defined(Q_OS_MACOS) IOReturn success = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn @@ -86,7 +86,7 @@ void PowerManagement::setIdle() #ifdef Q_OS_WIN SetThreadExecutionState(ES_CONTINUOUS); -#elif (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) +#elif defined(QBT_USES_DBUS) m_inhibitor->requestIdle(); #elif defined(Q_OS_MACOS) IOPMAssertionRelease(m_assertionID); diff --git a/src/gui/powermanagement/powermanagement.h b/src/gui/powermanagement/powermanagement.h index 0ef9fbfe4..f83192293 100644 --- a/src/gui/powermanagement/powermanagement.h +++ b/src/gui/powermanagement/powermanagement.h @@ -35,7 +35,7 @@ #include #endif -#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) +#ifdef QBT_USES_DBUS // Require DBus class PowerManagementInhibitor; #endif @@ -57,7 +57,7 @@ private: bool m_busy = false; -#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB) +#ifdef QBT_USES_DBUS PowerManagementInhibitor *m_inhibitor = nullptr; #endif #ifdef Q_OS_MACOS