Move feature macro declaration to build scripts

PR #18825.
This commit is contained in:
Chocobo1 2023-04-10 13:38:00 +08:00 committed by GitHub
parent 4a66d705b8
commit 5dcc14153f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 34 additions and 31 deletions

View file

@ -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()

2
configure vendored
View file

@ -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") :

View file

@ -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])

View file

@ -61,7 +61,7 @@
#include <QSysInfo>
#include <QVector>
#if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && defined(QT_DBUS_LIB)
#ifdef QBT_USES_DBUS
#include <QDBusInterface>
#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)
{

View file

@ -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<int>::max());

View file

@ -34,7 +34,6 @@
#include <QSpinBox>
#include <QTableWidget>
#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
};

View file

@ -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

View file

@ -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<int> m_storeNotificationTimeOut;
DBusNotifier *m_notifier = nullptr;
#endif

View file

@ -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());

View file

@ -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

View file

@ -38,14 +38,14 @@
#include <windows.h>
#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);

View file

@ -35,7 +35,7 @@
#include <IOKit/pwr_mgt/IOPMLib.h>
#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