Commit e62dd1a1 authored by Alexander Volkov's avatar Alexander Volkov
Browse files

Revert "Revert "Get rid of KDELibs4Support""

Summary:
This reverts commit 55603160.

"Get rid of KDELibs4Support" was reverted because Can* methods
of PowerManagement class returned incorrect values due to async
DBus calls. Use blocking DBus calls now.

Reviewers: davidedmundson, broulik, #plasma

Reviewed By: davidedmundson, #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D11744
parent 152400c1
......@@ -23,7 +23,7 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
endif()
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Widgets DBus X11Extras)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Activities Auth IdleTime Config DBusAddons Solid I18n GlobalAccel KIO NotifyConfig KDELibs4Support Wayland)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Activities Auth IdleTime Config DBusAddons Solid I18n GlobalAccel KIO NotifyConfig Wayland DocTools Crash Notifications)
find_package(KF5Screen CONFIG REQUIRED)
find_package(LibKWorkspace CONFIG REQUIRED)
......
......@@ -39,6 +39,7 @@ set(powerdevilcore_SRCS
powerdevilbrightnesslogic.cpp
powerdevilscreenbrightnesslogic.cpp
powerdevilkeyboardbrightnesslogic.cpp
powerdevilpowermanagement.cpp
brightnessosdwidget.cpp
kwinkscreenhelpereffect.cpp
)
......@@ -106,8 +107,8 @@ qt5_add_dbus_adaptor(powerdevil_SRCS org.kde.Solid.PowerManagement.PolicyAgent.x
powerdevilpolicyagent.h PowerDevil::PolicyAgent
powermanagementpolicyagentadaptor PowerManagementPolicyAgentAdaptor)
qt5_add_dbus_adaptor(powerdevil_SRCS ${KDE4_DBUS_INTERFACES_DIR}/kf5_org.freedesktop.PowerManagement.xml powerdevilfdoconnector.h PowerDevil::FdoConnector powermanagementfdoadaptor PowerManagementFdoAdaptor)
qt5_add_dbus_adaptor(powerdevil_SRCS ${KDE4_DBUS_INTERFACES_DIR}/kf5_org.freedesktop.PowerManagement.Inhibit.xml powerdevilfdoconnector.h PowerDevil::FdoConnector powermanagementinhibitadaptor PowerManagementInhibitAdaptor)
qt5_add_dbus_adaptor(powerdevil_SRCS org.freedesktop.PowerManagement.xml powerdevilfdoconnector.h PowerDevil::FdoConnector powermanagementfdoadaptor PowerManagementFdoAdaptor)
qt5_add_dbus_adaptor(powerdevil_SRCS org.freedesktop.PowerManagement.Inhibit.xml powerdevilfdoconnector.h PowerDevil::FdoConnector powermanagementinhibitadaptor PowerManagementInhibitAdaptor)
# Backends
......
......@@ -3,6 +3,7 @@ function(add_powerdevil_bundled_action _name)
add_library(powerdevil${_name}action_config MODULE
${actionconfig_SRCS})
target_link_libraries(powerdevil${_name}action_config
powerdevilcore
powerdevilui
Qt5::Widgets
KF5::CoreAddons
......@@ -18,7 +19,7 @@ add_powerdevil_bundled_action(brightnesscontrol KF5::GlobalAccel)
add_powerdevil_bundled_action(keyboardbrightnesscontrol)
add_powerdevil_bundled_action(dimdisplay)
add_powerdevil_bundled_action(runscript KF5::KIOCore KF5::KIOWidgets)
add_powerdevil_bundled_action(suspendsession KF5::KIOCore KF5::KIOWidgets KF5::Solid KF5::KDELibs4Support)
add_powerdevil_bundled_action(suspendsession KF5::KIOCore KF5::KIOWidgets)
if(HAVE_WIRELESS_SUPPORT)
add_powerdevil_bundled_action(wirelesspowersaving KF5::NetworkManagerQt KF5::BluezQt)
endif()
......@@ -30,14 +31,13 @@ qt5_add_dbus_interface(actionconfig_SRCS
add_library(powerdevilhandlebuttoneventsaction_config MODULE
${actionconfig_SRCS})
target_link_libraries(powerdevilhandlebuttoneventsaction_config
powerdevilcore
powerdevilui
Qt5::Widgets
KF5::CoreAddons
KF5::I18n
KF5::ConfigGui
KF5::Solid
KF5::XmlGui
KF5::KDELibs4Support
)
install(TARGETS powerdevilhandlebuttoneventsaction_config DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES powerdevilhandlebuttoneventsaction.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
......@@ -23,8 +23,7 @@
#include "suspendsession.h"
#include "upower_interface.h"
#include <Solid/Device>
#include <Solid/PowerManagement>
#include "powerdevilpowermanagement.h"
#include <KLocalizedString>
#include <KPluginFactory>
......@@ -94,17 +93,15 @@ QList< QPair< QString, QWidget* > > HandleButtonEventsConfig::buildUi()
QList<QComboBox *> boxes;
boxes << m_lidCloseCombo << m_powerButtonCombo;
QSet< Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates();
Q_FOREACH (QComboBox *box, boxes) {
box->addItem(QIcon::fromTheme("dialog-cancel"), i18n("Do nothing"), (uint)SuspendSession::None);
if (methods.contains(Solid::PowerManagement::SuspendState)) {
if (PowerManagement::instance()->canSuspend()) {
box->addItem(QIcon::fromTheme("system-suspend"), i18n("Suspend"), (uint)SuspendSession::ToRamMode);
}
if (methods.contains(Solid::PowerManagement::HibernateState)) {
if (PowerManagement::instance()->canHibernate()) {
box->addItem(QIcon::fromTheme("system-suspend-hibernate"), i18n("Hibernate"), (uint)SuspendSession::ToDiskMode);
}
if (methods.contains(Solid::PowerManagement::HybridSuspendState)) {
if (PowerManagement::instance()->canHybridSuspend()) {
box->addItem(QIcon::fromTheme("system-suspend-hybrid"), i18n("Hybrid suspend"), (uint)SuspendSession::SuspendHybridMode);
}
box->addItem(QIcon::fromTheme("system-shutdown"), i18n("Shut down"), (uint)SuspendSession::ShutdownMode);
......
......@@ -20,11 +20,11 @@
#include "suspendsessionconfig.h"
#include "powerdevilpowermanagement.h"
#include <QHBoxLayout>
#include <QSpinBox>
#include <Solid/PowerManagement>
#include <KComboBox>
#include <KLocalizedString>
#include <KPluginFactory>
......@@ -78,15 +78,13 @@ QList< QPair< QString, QWidget* > > SuspendSessionConfig::buildUi()
m_idleTime->setValue(0);
m_idleTime->setSuffix(i18n(" min"));
QSet< Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates();
if (methods.contains(Solid::PowerManagement::SuspendState)) {
if (PowerManagement::instance()->canSuspend()) {
m_comboBox->addItem(QIcon::fromTheme("system-suspend"), i18n("Suspend"), (uint)SuspendSession::ToRamMode);
}
if (methods.contains(Solid::PowerManagement::HibernateState)) {
if (PowerManagement::instance()->canHibernate()) {
m_comboBox->addItem(QIcon::fromTheme("system-suspend-hibernate"), i18n("Hibernate"), (uint)SuspendSession::ToDiskMode);
}
if (methods.contains(Solid::PowerManagement::HybridSuspendState)) {
if (PowerManagement::instance()->canHybridSuspend()) {
m_comboBox->addItem(QIcon::fromTheme("system-suspend-hybrid"), i18n("Hybrid suspend"), (uint)SuspendSession::SuspendHybridMode);
}
m_comboBox->addItem(QIcon::fromTheme("system-shutdown"), i18n("Shut down"), (uint)SuspendSession::ShutdownMode);
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.PowerManagement.Inhibit">
<method name="Inhibit">
<arg type="s" name="application" direction="in"/>
<arg type="s" name="reason" direction="in"/>
<arg type="u" name="cookie" direction="out"/>
</method>
<method name="UnInhibit">
<arg type="u" name="cookie" direction="in"/>
</method>
<signal name="HasInhibitChanged">
<arg type="b" name="has_inhibit" direction="out"/>
</signal>
<method name="HasInhibit">
<arg type="b" name="has_inhibit" direction="out"/>
</method>
</interface>
</node>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.PowerManagement">
<signal name="CanSuspendChanged">
<arg type="b" name="can_suspend" direction="out"/>
</signal>
<signal name="CanHibernateChanged">
<arg type="b" name="can_hibernate" direction="out"/>
</signal>
<signal name="CanHybridSuspendChanged">
<arg type="b" name="can_hybrid_suspend" direction="out"/>
</signal>
<signal name="PowerSaveStatusChanged">
<arg type="b" name="save_power" direction="out"/>
</signal>
<method name="Suspend"/>
<method name="Hibernate"/>
<method name="CanSuspend">
<arg type="b" name="can_suspend" direction="out"/>
</method>
<method name="CanHibernate">
<arg type="b" name="can_hibernate" direction="out"/>
</method>
<method name="CanHybridSuspend">
<arg type="b" name="can_hybrid_suspend" direction="out"/>
</method>
<method name="GetPowerSaveStatus">
<arg type="b" name="save_power" direction="out"/>
</method>
</interface>
</node>
/********************************************************************
Copyright 2016 Martin Gräßlin <mgraesslin@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "powerdevilpowermanagement.h"
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusServiceWatcher>
namespace PowerDevil {
static const QString s_fdoPowerService = QStringLiteral("org.freedesktop.PowerManagement");
static const QString s_fdoPowerPath = QStringLiteral("/org/freedesktop/PowerManagement");
class PowerManagementInstance : public PowerManagement
{
Q_OBJECT
public:
explicit PowerManagementInstance() : PowerManagement() {}
};
Q_GLOBAL_STATIC(PowerManagementInstance, s_instance)
class PowerManagement::Private
{
public:
Private(PowerManagement *q);
void update();
void setCanSuspend(bool set);
void setCanHibernate(bool set);
void setCanHybridSuspend(bool set);
bool serviceRegistered;
bool canSuspend;
bool canHibernate;
bool canHybridSuspend;
QScopedPointer<QDBusServiceWatcher> fdoPowerServiceWatcher;
private:
void updateProperty(const QString &dbusName, void (Private::*setter)(bool));
PowerManagement *q;
};
PowerManagement::Private::Private(PowerManagement *q)
: serviceRegistered(false)
, canSuspend(false)
, canHibernate(false)
, canHybridSuspend(false)
, fdoPowerServiceWatcher(new QDBusServiceWatcher(s_fdoPowerService, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForUnregistration | QDBusServiceWatcher::WatchForRegistration))
, q(q)
{
}
void PowerManagement::Private::update()
{
serviceRegistered = true;
updateProperty(QStringLiteral("CanSuspend"), &Private::setCanSuspend);
updateProperty(QStringLiteral("CanHibernate"), &Private::setCanHibernate);
updateProperty(QStringLiteral("CanHybridSuspend"), &Private::setCanHybridSuspend);
}
void PowerManagement::Private::updateProperty(const QString &dbusName, void (Private::*setter)(bool))
{
QDBusMessage message = QDBusMessage::createMethodCall(s_fdoPowerService,
s_fdoPowerPath,
s_fdoPowerService,
dbusName);
QDBusReply<bool> reply = QDBusConnection::sessionBus().call(message);
if (!reply.isValid()) {
return;
}
((this)->*setter)(reply.value());
}
void PowerManagement::Private::setCanHibernate(bool set)
{
if (canHibernate == set) {
return;
}
canHibernate = set;
q->canHibernateChanged();
}
void PowerManagement::Private::setCanSuspend(bool set)
{
if (canSuspend == set) {
return;
}
canSuspend = set;
q->canSuspendChanged();
}
void PowerManagement::Private::setCanHybridSuspend(bool set)
{
if (canHybridSuspend == set) {
return;
}
canHybridSuspend = set;
q->canHybridSuspendChanged();
}
PowerManagement *PowerManagement::instance()
{
return s_instance;
}
PowerManagement::PowerManagement()
: QObject()
, d(new Private(this))
{
connect(d->fdoPowerServiceWatcher.data(), &QDBusServiceWatcher::serviceRegistered, this, [this] { d->update(); });
connect(d->fdoPowerServiceWatcher.data(), &QDBusServiceWatcher::serviceUnregistered, this,
[this] {
d->serviceRegistered = false;
d->setCanSuspend(false);
d->setCanHibernate(false);
d->setCanHybridSuspend(false);
}
);
// check whether the service is registered
QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.DBus"),
QStringLiteral("/"),
QStringLiteral("org.freedesktop.DBus"),
QStringLiteral("ListNames"));
QDBusReply<QStringList> reply = QDBusConnection::sessionBus().call(message);
if (!reply.isValid()) {
return;
}
if (reply.value().contains(s_fdoPowerService)) {
d->update();
}
}
PowerManagement::~PowerManagement()
{
}
void PowerManagement::suspend()
{
if (!d->serviceRegistered) {
return;
}
if (!d->canSuspend) {
return;
}
QDBusMessage message = QDBusMessage::createMethodCall(s_fdoPowerService,
s_fdoPowerPath,
s_fdoPowerService,
QStringLiteral("Suspend"));
QDBusConnection::sessionBus().asyncCall(message);
}
void PowerManagement::hibernate()
{
if (!d->serviceRegistered) {
return;
}
if (!d->canHibernate) {
return;
}
QDBusMessage message = QDBusMessage::createMethodCall(s_fdoPowerService,
s_fdoPowerPath,
s_fdoPowerService,
QStringLiteral("Hibernate"));
QDBusConnection::sessionBus().asyncCall(message);
}
void PowerManagement::hybridSuspend()
{
// FIXME: Whether there is a support of this mode?
}
bool PowerManagement::canSuspend() const
{
return d->canSuspend;
}
bool PowerManagement::canHibernate() const
{
return d->canHibernate;
}
bool PowerManagement::canHybridSuspend() const
{
return d->canHybridSuspend;
}
} // namespace PowerDevil
#include "powerdevilpowermanagement.moc"
/********************************************************************
Copyright 2016 Martin Gräßlin <mgraesslin@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) version 3, or any
later version accepted by the membership of KDE e.V. (or its
successor approved by the membership of KDE e.V.), which shall
act as a proxy defined in Section 6 of version 3 of the license.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef POWERDEVIL_POWERMANAGEMENT_H
#define POWERDEVIL_POWERMANAGEMENT_H
#include <QObject>
namespace PowerDevil {
class Q_DECL_EXPORT PowerManagement : public QObject
{
Q_OBJECT
Q_PROPERTY(bool canSuspend READ canSuspend NOTIFY canSuspendChanged)
Q_PROPERTY(bool canHibernate READ canHibernate NOTIFY canHibernateChanged)
Q_PROPERTY(bool canHybridSuspend READ canHybridSuspend NOTIFY canHybridSuspendChanged)
public:
virtual ~PowerManagement();
bool canSuspend() const;
bool canHibernate() const;
bool canHybridSuspend() const;
static PowerManagement *instance();
public Q_SLOTS:
void suspend();
void hibernate();
void hybridSuspend();
Q_SIGNALS:
void canSuspendChanged();
void canHibernateChanged();
void canHybridSuspendChanged();
protected:
explicit PowerManagement();
private:
class Private;
QScopedPointer<Private> d;
};
} // namespace PowerDevil
#endif // POWERDEVIL_POWERMANAGEMENT_H
......@@ -15,9 +15,7 @@ kconfig_add_kcfg_files(kcm_powerdevil_activities_SRCS ../../PowerDevilSettings.k
add_library(kcm_powerdevilactivitiesconfig MODULE ${kcm_powerdevil_activities_SRCS})
target_link_libraries(kcm_powerdevilactivitiesconfig
KF5::Solid
KF5::Activities
KF5::KDELibs4Support
powerdevilconfigcommonprivate
)
......
......@@ -24,9 +24,10 @@
#include "../daemon/actions/bundled/suspendsession.h"
#include "powerdevilpowermanagement.h"
#include <KConfigGroup>
#include <KActivities/Consumer>
#include <Solid/PowerManagement>
#include <Solid/Battery>
#include <Solid/Device>
#include <actioneditwidget.h>
......@@ -91,13 +92,11 @@ void ActivityWidget::load()
using namespace PowerDevil::BundledActions;
QSet< Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates();
if (methods.contains(Solid::PowerManagement::SuspendState)) {
if (PowerDevil::PowerManagement::instance()->canSuspend()) {
m_ui->alwaysActionBox->addItem(QIcon::fromTheme("system-suspend"),
i18n("Suspend"), (uint)SuspendSession::ToRamMode);
}
if (methods.contains(Solid::PowerManagement::HibernateState)) {
if (PowerDevil::PowerManagement::instance()->canHibernate()) {
m_ui->alwaysActionBox->addItem(QIcon::fromTheme("system-suspend-hibernate"),
i18n("Hibernate"), (uint)SuspendSession::ToDiskMode);
}
......
......@@ -14,9 +14,7 @@ add_library(kcm_powerdevilglobalconfig MODULE ${kcm_powerdevil_global_SRCS})
target_link_libraries(kcm_powerdevilglobalconfig
KF5::ConfigWidgets
KF5::KIOWidgets
KF5::Solid
KF5::NotifyConfig
KF5::KDELibs4Support
powerdevilconfigcommonprivate
)
......
......@@ -24,10 +24,11 @@
#include "actions/bundled/suspendsession.h"
#include "powerdevilpowermanagement.h"
#include <Solid/Device>
#include <Solid/DeviceInterface>
#include <Solid/Battery>
#include <Solid/PowerManagement>
#include <QDBusMessage>
#include <QDBusReply>
......@@ -101,13 +102,11 @@ void GeneralPage::fillUi()
}
}
QSet< Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates();
BatteryCriticalCombo->addItem(QIcon::fromTheme("dialog-cancel"), i18n("Do nothing"), PowerDevil::BundledActions::SuspendSession::None);
if (methods.contains(Solid::PowerManagement::SuspendState)) {
if (PowerDevil::PowerManagement::instance()->canSuspend()) {
BatteryCriticalCombo->addItem(QIcon::fromTheme("system-suspend"), i18n("Suspend"), PowerDevil::BundledActions::SuspendSession::ToRamMode);
}
if (methods.contains(Solid::PowerManagement::HibernateState)) {
if (PowerDevil::PowerManagement::instance()->canHibernate()) {
BatteryCriticalCombo->addItem(QIcon::fromTheme("system-suspend-hibernate"), i18n("Hibernate"), PowerDevil::BundledActions::SuspendSession::ToDiskMode);
}
BatteryCriticalCombo->addItem(QIcon::fromTheme("system-shutdown"), i18n("Shut down"), PowerDevil::BundledActions::SuspendSession::ShutdownMode);
......
......@@ -15,10 +15,8 @@ add_library(kcm_powerdevilprofilesconfig MODULE ${kcm_powerdevil_profiles_SRCS})
target_link_libraries(kcm_powerdevilprofilesconfig
KF5::KIOWidgets
KF5::Solid
KF5::ConfigGui
KF5::ConfigWidgets
KF5::KDELibs4Support
powerdevilui
powerdevilconfigcommonprivate
)
......
......@@ -24,6 +24,7 @@
#include <powerdevilactionconfig.h>
#include <powerdevilprofilegenerator.h>
#include <powerdevilpowermanagement.h>
#include <powerdevil_debug.h>
......@@ -51,7 +52,6 @@
#include <Solid/Battery>
#include <Solid/Device>
#include <Solid/PowerManagement>
K_PLUGIN_FACTORY(PowerDevilProfilesKCMFactory,
registerPlugin<EditPage>();
......@@ -80,10 +80,9 @@ EditPage::EditPage(QWidget *parent, const QVariantList &args)
if (m_profilesConfig->groupList().isEmpty()) {
// Use the generator
QSet <Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates();
PowerDevil::ProfileGenerator::generateProfiles(
methods.contains(Solid::PowerManagement::SuspendState),
methods.contains(Solid::PowerManagement::HibernateState)
PowerDevil::PowerManagement::instance()->canSuspend(),
PowerDevil::PowerManagement::instance()->canHibernate()
);
m_profilesConfig->reparseConfiguration();
}
......@@ -196,10 +195,9 @@ void EditPage::restoreDefaultProfiles()
"Are you sure you want to continue?"), i18n("Restore Default Profiles"));
if (ret == KMessageBox::Continue) {
qCDebug(POWERDEVIL) << "Restoring defaults.";
QSet <Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates();
PowerDevil::ProfileGenerator::generateProfiles(
methods.contains(Solid::PowerManagement::SuspendState),
methods.contains(Solid::PowerManagement::HibernateState)
PowerDevil::PowerManagement::instance()->canSuspend(),
PowerDevil::PowerManagement::instance()->canHibernate()
);
load();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment