Make QtDBus dependency optional

This commit is contained in:
Christophe Dumez
2011-03-07 20:22:35 +00:00
parent 82e41f36ee
commit b6c3189fe3
11 changed files with 115 additions and 35 deletions

View File

@@ -43,9 +43,6 @@
#include <QCloseEvent>
#include <QShortcut>
#include <QScrollBar>
#ifdef Q_WS_X11
#include <QDBusInterface>
#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);
}

View File

@@ -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 <QDBusInterface>
#include <QDBusMessage>
#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());

View File

@@ -30,7 +30,7 @@
#include <QtGlobal>
#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);

View File

@@ -38,32 +38,32 @@
#include <IOKit/pwr_mgt/IOPMLib.h>
#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
};

View File

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

View File

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