Commit aba84003 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Bundle the DPMS action

It is the only action that is not bundled and there does not seem to be a good reason for this

If we can assume that all actions are bundled then we can simplify the code a bit
parent 04a25259
......@@ -14,6 +14,11 @@ set(powerdevil_bundled_actions_SRCS
actions/bundled/dimdisplay.cpp
actions/bundled/runscript.cpp
actions/bundled/handlebuttonevents.cpp
actions/bundled/dpms.cpp
actions/bundled/abstractdpmshelper.cpp
actions/bundled/xcbdpmshelper.cpp
actions/bundled/waylanddpmshelper.cpp
${PowerDevil_SOURCE_DIR}/daemon/kwinkscreenhelpereffect.cpp
)
if(HAVE_WIRELESS_SUPPORT)
......@@ -82,7 +87,9 @@ target_link_libraries(powerdevilcore
KF5::WidgetsAddons
KF5::Notifications
KF5::XmlGui
KF5::WaylandClient
PW::KWorkspace
XCB::DPMS
)
if(HAVE_WIRELESS_SUPPORT)
......
install(FILES powerdevilaction.desktop DESTINATION ${KDE_INSTALL_KSERVICETYPES5DIR})
add_subdirectory(bundled)
add_subdirectory(dpms)
......@@ -20,6 +20,7 @@ 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)
add_powerdevil_bundled_action(dpms)
if(HAVE_WIRELESS_SUPPORT)
add_powerdevil_bundled_action(wirelesspowersaving KF5::NetworkManagerQt KF5::BluezQt)
endif()
......
......@@ -19,7 +19,7 @@
***************************************************************************/
#include "powerdevildpmsaction.h"
#include "dpms.h"
#include "abstractdpmshelper.h"
#include "xcbdpmshelper.h"
#include "waylanddpmshelper.h"
......@@ -43,9 +43,10 @@
#include <KPluginFactory>
#include <KSharedConfig>
K_PLUGIN_FACTORY(PowerDevilDPMSActionFactory, registerPlugin<PowerDevilDPMSAction>(); )
namespace PowerDevil {
namespace BundledActions {
PowerDevilDPMSAction::PowerDevilDPMSAction(QObject* parent, const QVariantList &args)
DPMS::DPMS(QObject* parent)
: Action(parent)
, m_helper()
{
......@@ -57,20 +58,12 @@ PowerDevilDPMSAction::PowerDevilDPMSAction(QObject* parent, const QVariantList &
m_helper.reset(new WaylandDpmsHelper);
}
// Is the action being loaded outside the core?
if (args.size() > 0) {
if (args.first().toBool()) {
qCDebug(POWERDEVIL) << "Action loaded from outside the core, skipping early init";
return;
}
}
// Pretend we're unloading profiles here, as if the action is not enabled, DPMS should be switched off.
onProfileUnload();
// Listen to the policy agent
connect(PowerDevil::PolicyAgent::instance(), &PowerDevil::PolicyAgent::unavailablePoliciesChanged,
this, &PowerDevilDPMSAction::onUnavailablePoliciesChanged);
this, &DPMS::onUnavailablePoliciesChanged);
// inhibitions persist over kded module unload/load
m_inhibitScreen = PowerDevil::PolicyAgent::instance()->unavailablePolicies() & PowerDevil::PolicyAgent::ChangeScreenSettings;
......@@ -98,14 +91,14 @@ PowerDevilDPMSAction::PowerDevilDPMSAction(QObject* parent, const QVariantList &
});
}
PowerDevilDPMSAction::~PowerDevilDPMSAction() = default;
DPMS::~DPMS() = default;
bool PowerDevilDPMSAction::isSupported()
bool DPMS::isSupported()
{
return !m_helper.isNull() && m_helper->isSupported();
}
void PowerDevilDPMSAction::onProfileUnload()
void DPMS::onProfileUnload()
{
if (!isSupported()) {
return;
......@@ -113,7 +106,7 @@ void PowerDevilDPMSAction::onProfileUnload()
m_helper->profileUnloaded();
}
void PowerDevilDPMSAction::onWakeupFromIdle()
void DPMS::onWakeupFromIdle()
{
if (isSupported()) {
m_helper->stopFade();
......@@ -124,7 +117,7 @@ void PowerDevilDPMSAction::onWakeupFromIdle()
}
}
void PowerDevilDPMSAction::onIdleTimeout(int msec)
void DPMS::onIdleTimeout(int msec)
{
// Do not inhibit anything even if idleTimeout reaches because we are inhibit
if (m_inhibitScreen) {
......@@ -147,14 +140,14 @@ void PowerDevilDPMSAction::onIdleTimeout(int msec)
}
}
void PowerDevilDPMSAction::setKeyboardBrightnessHelper(int brightness)
void DPMS::setKeyboardBrightnessHelper(int brightness)
{
trigger({
{"KeyboardBrightness", QVariant::fromValue(brightness)}
});
}
void PowerDevilDPMSAction::onProfileLoad()
void DPMS::onProfileLoad()
{
if (!isSupported()) {
return;
......@@ -162,7 +155,7 @@ void PowerDevilDPMSAction::onProfileLoad()
m_helper->profileLoaded();
}
void PowerDevilDPMSAction::triggerImpl(const QVariantMap& args)
void DPMS::triggerImpl(const QVariantMap& args)
{
QString KEYBOARD_BRIGHTNESS = QStringLiteral("KeyboardBrightness");
if (args.contains(KEYBOARD_BRIGHTNESS)) {
......@@ -180,7 +173,7 @@ void PowerDevilDPMSAction::triggerImpl(const QVariantMap& args)
m_helper->trigger(args.value(QStringLiteral("Type")).toString());
}
bool PowerDevilDPMSAction::loadAction(const KConfigGroup& config)
bool DPMS::loadAction(const KConfigGroup& config)
{
m_idleTime = config.readEntry<int>("idleTime", -1);
if (m_idleTime > 0) {
......@@ -192,13 +185,13 @@ bool PowerDevilDPMSAction::loadAction(const KConfigGroup& config)
return true;
}
bool PowerDevilDPMSAction::onUnloadAction()
bool DPMS::onUnloadAction()
{
m_idleTime = 0;
return Action::onUnloadAction();
}
void PowerDevilDPMSAction::onUnavailablePoliciesChanged(PowerDevil::PolicyAgent::RequiredPolicies policies)
void DPMS::onUnavailablePoliciesChanged(PowerDevil::PolicyAgent::RequiredPolicies policies)
{
// only take action if screen inhibit changed
PowerDevil::PolicyAgent::RequiredPolicies oldPolicy = m_inhibitScreen;
......@@ -219,7 +212,7 @@ void PowerDevilDPMSAction::onUnavailablePoliciesChanged(PowerDevil::PolicyAgent:
}
}
void PowerDevilDPMSAction::lockScreen()
void DPMS::lockScreen()
{
QDBusConnection::sessionBus().asyncCall(QDBusMessage::createMethodCall("org.freedesktop.ScreenSaver",
"/ScreenSaver",
......@@ -227,4 +220,5 @@ void PowerDevilDPMSAction::lockScreen()
"Lock"));
}
#include "powerdevildpmsaction.moc"
}
}
......@@ -28,14 +28,17 @@
class AbstractDpmsHelper;
class PowerDevilDPMSAction : public PowerDevil::Action
namespace PowerDevil {
namespace BundledActions {
class DPMS : public PowerDevil::Action
{
Q_OBJECT
Q_DISABLE_COPY(PowerDevilDPMSAction)
Q_DISABLE_COPY(DPMS)
public:
explicit PowerDevilDPMSAction(QObject *parent, const QVariantList &);
~PowerDevilDPMSAction() override;
explicit DPMS(QObject *parent);
~DPMS() override;
protected:
void onProfileUnload() override;
......@@ -66,4 +69,7 @@ private:
};
}
}
#endif // POWERDEVILDPMSACTION_H
......@@ -17,7 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#include "powerdevildpmsactionconfig.h"
#include "dpmsconfig.h"
#include <QSpinBox>
......@@ -65,4 +65,4 @@ QList< QPair< QString, QWidget* > > PowerDevilDPMSActionConfig::buildUi()
return retlist;
}
#include "powerdevildpmsactionconfig.moc"
#include "dpmsconfig.moc"
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=PowerDevil/Action
X-KDE-Library=powerdevildpmsaction
Icon=preferences-desktop-screensaver
Name=Screen Energy Saving
Name[ar]=حِفظ طاقة الشاشة
......@@ -102,7 +101,7 @@ Comment[zh_CN]=控制屏幕电源管理设置
Comment[zh_TW]=控制 DPMS 設定
X-KDE-PowerDevil-Action-ID=DPMSControl
X-KDE-PowerDevil-Action-IsBundled=false
X-KDE-PowerDevil-Action-IsBundled=true
X-KDE-PowerDevil-Action-ForceInstantLoad=true
X-KDE-PowerDevil-Action-UIComponentLibrary=powerdevildpmsaction_config
X-KDE-PowerDevil-Action-ConfigPriority=98
......
include_directories(${PowerDevil_SOURCE_DIR}/daemon
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR})
set(powerdevildpmsaction_SRCS
${CMAKE_CURRENT_BINARY_DIR}/../../powerdevil_debug.cpp
powerdevildpmsaction.cpp
abstractdpmshelper.cpp
xcbdpmshelper.cpp
waylanddpmshelper.cpp
${PowerDevil_SOURCE_DIR}/daemon/kwinkscreenhelpereffect.cpp
)
add_library(powerdevildpmsaction MODULE ${powerdevildpmsaction_SRCS})
target_link_libraries(powerdevildpmsaction
Qt::X11Extras
XCB::XCB
XCB::DPMS
KF5::CoreAddons
KF5::ConfigGui
KF5::I18n
KF5::WaylandClient
Qt::Widgets
powerdevilcore)
install(TARGETS powerdevildpmsaction DESTINATION ${KDE_INSTALL_PLUGINDIR})
install(FILES powerdevildpmsaction.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR})
# Action config
set(dpmsconfig_SRCS powerdevildpmsactionconfig.cpp)
add_library(powerdevildpmsaction_config MODULE
${dpmsconfig_SRCS})
target_link_libraries(powerdevildpmsaction_config
KF5::CoreAddons
KF5::ConfigGui
KF5::I18n
Qt::Widgets
powerdevilui)
install(TARGETS powerdevildpmsaction_config DESTINATION ${KDE_INSTALL_PLUGINDIR})
......@@ -39,6 +39,7 @@
#include "actions/bundled/dimdisplay.h"
#include "actions/bundled/runscript.h"
#include "actions/bundled/handlebuttonevents.h"
#include "actions/bundled/dpms.h"
#ifdef HAVE_WIRELESS_SUPPORT
#include "actions/bundled/wirelesspowersaving.h"
#endif
......@@ -130,6 +131,7 @@ void ActionPool::init(PowerDevil::Core *parent)
m_actionPool.insert(QStringLiteral("DimDisplay"), new BundledActions::DimDisplay(parent));
m_actionPool.insert(QStringLiteral("RunScript"), new BundledActions::RunScript(parent));
m_actionPool.insert(QStringLiteral("HandleButtonEvents"), new BundledActions::HandleButtonEvents(parent));
m_actionPool.insert(QStringLiteral("DPMSControl"), new BundledActions::DPMS(parent));
#ifdef HAVE_WIRELESS_SUPPORT
m_actionPool.insert(QStringLiteral("WirelessPowerSaving"), new BundledActions::WirelessPowerSaving(parent));
#endif
......
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