From b6c3189fe3dc357a9b9c6e3fc94b14f5a70f35d9 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 7 Mar 2011 20:22:35 +0000 Subject: [PATCH] Make QtDBus dependency optional --- Changelog | 1 + configure | 43 +++++++++++++++++++++++++ qbittorrent.qc | 2 ++ qcm/qt-dbus.qcm | 31 ++++++++++++++++++ src/mainwindow.cpp | 24 +++++++------- src/misc.cpp | 4 +-- src/powermanagement/powermanagement.cpp | 8 ++--- src/powermanagement/powermanagement.h | 22 ++++++------- src/powermanagement/powermanagement.pri | 6 ++-- src/preferences/options_imp.cpp | 7 ++-- unixconf.pri | 2 +- 11 files changed, 115 insertions(+), 35 deletions(-) create mode 100644 qcm/qt-dbus.qcm diff --git a/Changelog b/Changelog index 3567c7fdb..b26b62638 100644 --- a/Changelog +++ b/Changelog @@ -8,6 +8,7 @@ - FEATURE: Added option to disable program exit confirmation - FEATURE: Added per-torrent ratio limiting (Christian Kandeler) - BUGFIX: Fix compilation with namespaced Qt (Christian Kandeler) + - OTHER: Make QtDBus dependency optional (X11) * Sun Jan 9 2011 - Christophe Dumez - v2.6.0 - FEATURE: Use system icons (Linux, Qt >= 4.6) diff --git a/configure b/configure index cdde7c7da..1dc591b4f 100755 --- a/configure +++ b/configure @@ -22,6 +22,7 @@ Dependency options: --disable-gui Disable qBittorrent Graphical user interface for headless running + --disable-qt-dbus Disable use of qt-dbus --with-libboost-inc=[path] Path to libboost include files --with-libboost-lib=[path] Path to libboost library @@ -162,6 +163,11 @@ while [ $# -gt 0 ]; do shift ;; + --disable-qt-dbus) + QC_DISABLE_qt_dbus="Y" + shift + ;; + --with-libboost-inc=*) QC_WITH_LIBBOOST_INC=$optarg shift @@ -215,6 +221,7 @@ echo DATADIR=$DATADIR echo EX_QTDIR=$EX_QTDIR echo QC_ENABLE_DEBUG=$QC_ENABLE_DEBUG echo QC_DISABLE_GUI=$QC_DISABLE_GUI +echo QC_DISABLE_qt_dbus=$QC_DISABLE_qt_dbus echo QC_WITH_LIBBOOST_INC=$QC_WITH_LIBBOOST_INC echo QC_WITH_LIBBOOST_LIB=$QC_WITH_LIBBOOST_LIB echo QC_DISABLE_libnotify=$QC_DISABLE_libnotify @@ -355,6 +362,38 @@ public: return(QT_VERSION >= 0x040500); } }; +#line 1 "qt-dbus.qcm" +/* +-----BEGIN QCMOD----- +name: qt-dbus +-----END QCMOD----- +*/ +// see Conf::findPkgConfig +class qc_qt_dbus : public ConfObj +{ +public: + qc_qt_dbus(Conf *c) : ConfObj(c) {} + QString name() const { return "QtDBus >= 4.5"; } + QString shortname() const { return "qt-dbus"; } + QString checkString() const { + if(!conf->getenv("QC_DISABLE_qt_dbus").isEmpty() || !conf->getenv("QC_DISABLE_GUI").isEmpty()) + return ""; + return ConfObj::checkString(); + } + bool exec(){ + if(!conf->getenv("QC_DISABLE_qt_dbus").isEmpty() || !conf->getenv("QC_DISABLE_GUI").isEmpty()) + return false; + QStringList incs; + QString req_ver = "4.5.0"; + QString version, libs, other; + VersionMode mode = VersionMin; + if(conf->findPkgConfig("QtDBus", mode, req_ver, &version, &incs, &libs, &other)) { + conf->addExtra("CONFIG += dbus"); + return true; + } + return false; + } +}; #line 1 "pkg-config.qcm" /* -----BEGIN QCMOD----- @@ -645,6 +684,9 @@ cat >$1/modules_new.cpp <required = true; o->disabled = false; + o = new qc_qt_dbus(conf); + o->required = false; + o->disabled = false; o = new qc_pkg_config(conf); o->required = true; o->disabled = false; @@ -1610,6 +1652,7 @@ export DATADIR export EX_QTDIR export QC_ENABLE_DEBUG export QC_DISABLE_GUI +export QC_DISABLE_qt_dbus export QC_WITH_LIBBOOST_INC export QC_WITH_LIBBOOST_LIB export QC_DISABLE_libnotify diff --git a/qbittorrent.qc b/qbittorrent.qc index ec5bf5feb..59726552b 100644 --- a/qbittorrent.qc +++ b/qbittorrent.qc @@ -6,6 +6,8 @@ + + diff --git a/qcm/qt-dbus.qcm b/qcm/qt-dbus.qcm new file mode 100644 index 000000000..1448c8d4f --- /dev/null +++ b/qcm/qt-dbus.qcm @@ -0,0 +1,31 @@ +/* +-----BEGIN QCMOD----- +name: qt-dbus +-----END QCMOD----- +*/ +// see Conf::findPkgConfig +class qc_qt_dbus : public ConfObj +{ +public: + qc_qt_dbus(Conf *c) : ConfObj(c) {} + QString name() const { return "QtDBus >= 4.5"; } + QString shortname() const { return "qt-dbus"; } + QString checkString() const { + if(!conf->getenv("QC_DISABLE_qt_dbus").isEmpty() || !conf->getenv("QC_DISABLE_GUI").isEmpty()) + return ""; + return ConfObj::checkString(); + } + bool exec(){ + if(!conf->getenv("QC_DISABLE_qt_dbus").isEmpty() || !conf->getenv("QC_DISABLE_GUI").isEmpty()) + return false; + QStringList incs; + QString req_ver = "4.5.0"; + QString version, libs, other; + VersionMode mode = VersionMin; + if(conf->findPkgConfig("QtDBus", mode, req_ver, &version, &incs, &libs, &other)) { + conf->addExtra("CONFIG += dbus"); + return true; + } + return false; + } +}; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 55c1defdc..5284c2ecd 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -43,9 +43,6 @@ #include #include #include -#ifdef Q_WS_X11 -#include -#endif #include "mainwindow.h" #include "transferlistwidget.h" @@ -235,11 +232,14 @@ MainWindow::MainWindow(QWidget *parent, QStringList torrentCmdLine) : QMainWindo autoShutdownGroup->setExclusive(true); autoShutdownGroup->addAction(actionAutoShutdown_Disabled); autoShutdownGroup->addAction(actionAutoExit_qBittorrent); +#if !defined(Q_WS_X11) || defined(QT_DBUS_LIB) autoShutdownGroup->addAction(actionAutoShutdown_system); autoShutdownGroup->addAction(actionAutoSuspend_system); - actionAutoExit_qBittorrent->setChecked(pref.shutdownqBTWhenDownloadsComplete()); actionAutoShutdown_system->setChecked(pref.shutdownWhenDownloadsComplete()); actionAutoSuspend_system->setChecked(pref.suspendWhenDownloadsComplete()); +#endif + actionAutoExit_qBittorrent->setChecked(pref.shutdownqBTWhenDownloadsComplete()); + if(!autoShutdownGroup->checkedAction()) actionAutoShutdown_Disabled->setChecked(true); @@ -997,12 +997,12 @@ void MainWindow::loadPreferences(bool configure_session) { if(pref.preventFromSuspend()) { - preventTimer->start(PREVENT_SUSPEND_INTERVAL); + preventTimer->start(PREVENT_SUSPEND_INTERVAL); } else { - preventTimer->stop(); - m_pwr->setActivityState(false); + preventTimer->stop(); + m_pwr->setActivityState(false); } const uint new_refreshInterval = pref.getRefreshInterval(); @@ -1336,9 +1336,9 @@ void MainWindow::on_actionAutoShutdown_system_toggled(bool enabled) void MainWindow::checkForActiveTorrents() { - const TorrentStatusReport report = transferList->getSourceModel()->getTorrentStatusReport(); - if(report.nb_active > 0) // Active torrents are present; prevent system from suspend - m_pwr->setActivityState(true); - else - m_pwr->setActivityState(false); + const TorrentStatusReport report = transferList->getSourceModel()->getTorrentStatusReport(); + if(report.nb_active > 0) // Active torrents are present; prevent system from suspend + m_pwr->setActivityState(true); + else + m_pwr->setActivityState(false); } diff --git a/src/misc.cpp b/src/misc.cpp index eaa41f98e..85a79927e 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -71,7 +71,7 @@ const int UNLEN = 256; #endif #ifndef DISABLE_GUI -#ifdef Q_WS_X11 +#if defined(Q_WS_X11) && defined(QT_DBUS_LIB) #include #include #endif @@ -206,7 +206,7 @@ long long misc::freeDiskSpaceOnPath(QString path) { #ifndef DISABLE_GUI void misc::shutdownComputer(bool sleep) { -#ifdef Q_WS_X11 +#if defined(Q_WS_X11) && defined(QT_DBUS_LIB) // Use dbus to power off the system // dbus-send --print-reply --system --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown QDBusInterface computer("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.SystemPowerManagement", QDBusConnection::systemBus()); diff --git a/src/powermanagement/powermanagement.cpp b/src/powermanagement/powermanagement.cpp index 6105ea47a..dcbd8ad8f 100644 --- a/src/powermanagement/powermanagement.cpp +++ b/src/powermanagement/powermanagement.cpp @@ -30,7 +30,7 @@ #include -#ifdef Q_WS_X11 +#if defined(Q_WS_X11) && defined(QT_DBUS_LIB) #include "powermanagement_x11.h" #endif #include "powermanagement.h" @@ -45,7 +45,7 @@ PowerManagement::PowerManagement(QObject *parent) : QObject(parent), m_busy(false) { -#ifdef Q_WS_X11 +#if defined(Q_WS_X11) && defined(QT_DBUS_LIB) m_inhibitor = new PowerManagementInhibitor(this); #endif } @@ -67,7 +67,7 @@ void PowerManagement::setBusy() #ifdef Q_WS_WIN SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED); -#elif defined(Q_WS_X11) +#elif defined(Q_WS_X11) && defined(QT_DBUS_LIB) m_inhibitor->RequestBusy(); #elif defined(Q_WS_MAC) IOReturn success = IOPMAssertionCreate(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, &m_assertionID); @@ -82,7 +82,7 @@ void PowerManagement::setIdle() #ifdef Q_WS_WIN SetThreadExecutionState(ES_CONTINUOUS); -#elif defined(Q_WS_X11) +#elif defined(Q_WS_X11) && defined(QT_DBUS_LIB) m_inhibitor->RequestIdle(); #elif defined(Q_WS_MAC) IOPMAssertionRelease(m_assertionID); diff --git a/src/powermanagement/powermanagement.h b/src/powermanagement/powermanagement.h index 5397957f0..3234d22b1 100644 --- a/src/powermanagement/powermanagement.h +++ b/src/powermanagement/powermanagement.h @@ -38,32 +38,32 @@ #include #endif -#ifdef Q_WS_X11 +#if defined(Q_WS_X11) && defined(QT_DBUS_LIB) // Require DBus class PowerManagementInhibitor; #endif class PowerManagement : public QObject { - Q_OBJECT + Q_OBJECT public: - PowerManagement(QObject *parent = 0); - virtual ~PowerManagement(); + PowerManagement(QObject *parent = 0); + virtual ~PowerManagement(); - void setActivityState(bool busy); + void setActivityState(bool busy); private: - bool m_busy; + bool m_busy; - void setBusy(); - void setIdle(); + void setBusy(); + void setIdle(); -#ifdef Q_WS_X11 - PowerManagementInhibitor *m_inhibitor; +#if defined(Q_WS_X11) && defined(QT_DBUS_LIB) + PowerManagementInhibitor *m_inhibitor; #endif #ifdef Q_WS_MAC - IOPMAssertionID m_assertionID; + IOPMAssertionID m_assertionID; #endif }; diff --git a/src/powermanagement/powermanagement.pri b/src/powermanagement/powermanagement.pri index 42602b0d1..d5834d935 100644 --- a/src/powermanagement/powermanagement.pri +++ b/src/powermanagement/powermanagement.pri @@ -3,7 +3,7 @@ INCLUDEPATH += $$PWD HEADERS += $$PWD/powermanagement.h SOURCES += $$PWD/powermanagement.cpp -unix:!macx { - HEADERS += $$PWD/powermanagement_x11.h - SOURCES += $$PWD/powermanagement_x11.cpp +unix:!macx:dbus { + HEADERS += $$PWD/powermanagement_x11.h + SOURCES += $$PWD/powermanagement_x11.cpp } diff --git a/src/preferences/options_imp.cpp b/src/preferences/options_imp.cpp index 6d747ee6a..07e092974 100644 --- a/src/preferences/options_imp.cpp +++ b/src/preferences/options_imp.cpp @@ -132,6 +132,9 @@ options_imp::options_imp(QWidget *parent): connect(checkShowSplash, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkProgramExitConfirm, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); connect(checkPreventFromSuspend, SIGNAL(toggled(bool)), this, SLOT(enableApplyButton())); +#if defined(Q_WS_X11) && !defined(QT_DBUS_LIB) + checkPreventFromSuspend->setDisabled(true); +#endif // Downloads tab connect(textSavePath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); connect(textTempPath, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); @@ -231,7 +234,7 @@ void options_imp::initializeLanguageCombo() QLocale locale(localeStr); const QString country = locale.name().split("_").last().toLower(); QString language_name = languageToLocalizedString(locale.language(), country); - comboI18n->addItem(/*QIcon(":/Icons/flags/"+country+".png"), */language_name, locale.name()); + comboI18n->addItem(/*QIcon(":/Icons/flags/"+country+".png"), */language_name, locale.name()); qDebug() << "Supported locale:" << locale.name(); } } @@ -917,7 +920,7 @@ bool options_imp::isSlashScreenDisabled() const { } bool options_imp::preventFromSuspend() const { - return checkPreventFromSuspend->isChecked(); + return checkPreventFromSuspend->isChecked(); } bool options_imp::preAllocateAllFiles() const { diff --git a/unixconf.pri b/unixconf.pri index 342e3509f..8cc8dd2fb 100644 --- a/unixconf.pri +++ b/unixconf.pri @@ -2,7 +2,7 @@ include(conf.pri) # COMPILATION SPECIFIC -!nox { +!nox:dbus { QT += dbus } QMAKE_LFLAGS_APP += -rdynamic