diff --git a/daemon/actions/bundled/handlebuttonevents.cpp b/daemon/actions/bundled/handlebuttonevents.cpp index 7ec9adcf..98df2e71 100644 --- a/daemon/actions/bundled/handlebuttonevents.cpp +++ b/daemon/actions/bundled/handlebuttonevents.cpp @@ -1,256 +1,266 @@ /*************************************************************************** * Copyright (C) 2010 by Dario Freddi * * Copyright (C) 2015 by Kai Uwe Broulik * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "handlebuttonevents.h" #include "handlebuttoneventsadaptor.h" #include "suspendsession.h" #include #include #include #include #include #include #include #include #include #include #include #include namespace PowerDevil { namespace BundledActions { HandleButtonEvents::HandleButtonEvents(QObject *parent) : Action(parent) , m_screenConfiguration(nullptr) { new HandleButtonEventsAdaptor(this); // We enforce no policies here - after all, we just call other actions - which have their policies. setRequiredPolicies(PowerDevil::PolicyAgent::None); connect(backend(), SIGNAL(buttonPressed(PowerDevil::BackendInterface::ButtonType)), this, SLOT(onButtonPressed(PowerDevil::BackendInterface::ButtonType))); KActionCollection* actionCollection = new KActionCollection( this ); actionCollection->setComponentDisplayName(i18nc("Name for powerdevil shortcuts category", "Power Management")); KGlobalAccel *accel = KGlobalAccel::self(); QAction *globalAction = actionCollection->addAction("Sleep"); globalAction->setText(i18nc("@action:inmenu Global shortcut", "Suspend")); accel->setGlobalShortcut(globalAction, Qt::Key_Sleep); connect(globalAction, SIGNAL(triggered(bool)), SLOT(suspendToRam())); globalAction = actionCollection->addAction("Hibernate"); globalAction->setText(i18nc("@action:inmenu Global shortcut", "Hibernate")); accel->setGlobalShortcut(globalAction, Qt::Key_Hibernate); connect(globalAction, SIGNAL(triggered(bool)), SLOT(suspendToDisk())); globalAction = actionCollection->addAction("PowerOff"); globalAction->setText(i18nc("@action:inmenu Global shortcut", "Power Off")); accel->setGlobalShortcut(globalAction, Qt::Key_PowerOff); connect(globalAction, SIGNAL(triggered(bool)), SLOT(powerOffButtonTriggered())); + globalAction = actionCollection->addAction("PowerDown"); + globalAction->setText(i18nc("@action:inmenu Global shortcut", "Power Down")); + accel->setGlobalShortcut(globalAction, Qt::Key_PowerDown); + connect(globalAction, &QAction::triggered, this, &HandleButtonEvents::powerDownButtonTriggered); + connect(new KScreen::GetConfigOperation(KScreen::GetConfigOperation::NoEDID), &KScreen::ConfigOperation::finished, this, [this](KScreen::ConfigOperation *op) { m_screenConfiguration = qobject_cast(op)->config(); checkOutputs(); KScreen::ConfigMonitor::instance()->addConfig(m_screenConfiguration); connect(KScreen::ConfigMonitor::instance(), &KScreen::ConfigMonitor::configurationChanged, this, &HandleButtonEvents::checkOutputs); }); } HandleButtonEvents::~HandleButtonEvents() { } bool HandleButtonEvents::isSupported() { //we handles keyboard shortcuts in our button handling, users always have a keyboard return true; } void HandleButtonEvents::onProfileUnload() { m_lidAction = 0; m_powerButtonAction = 0; } void HandleButtonEvents::onWakeupFromIdle() { // } void HandleButtonEvents::onIdleTimeout(int msec) { Q_UNUSED(msec) } void HandleButtonEvents::onProfileLoad() { // } void HandleButtonEvents::onButtonPressed(BackendInterface::ButtonType type) { switch (type) { case BackendInterface::LidClose: if (!triggersLidAction()) { qCWarning(POWERDEVIL) << "Lid action was suppressed because an external monitor is present"; return; } processAction(m_lidAction); break; case BackendInterface::LidOpen: // In this case, let's send a wakeup event KIdleTime::instance()->simulateUserActivity(); break; case BackendInterface::PowerButton: processAction(m_powerButtonAction); break; case BackendInterface::SleepButton: processAction(m_sleepButtonAction); break; case BackendInterface::HibernateButton: processAction(m_hibernateButtonAction); break; default: break; } } void HandleButtonEvents::processAction(uint action) { // Basically, we simply trigger other actions :) switch (static_cast(action)) { case SuspendSession::TurnOffScreenMode: // Turn off screen triggerAction("DPMSControl", QStringLiteral("TurnOff")); break; case SuspendSession::ToggleScreenOnOffMode: // Toggle screen on/off triggerAction("DPMSControl", QStringLiteral("ToggleOnOff")); break; default: triggerAction("SuspendSession", action); break; } } void HandleButtonEvents::triggerAction(const QString &action, const QVariant &type) { PowerDevil::Action *helperAction = ActionPool::instance()->loadAction(action, KConfigGroup(), core()); if (helperAction) { helperAction->trigger({ {QStringLiteral("Type"), type}, {QStringLiteral("Explicit"), true} }); } } void HandleButtonEvents::triggerImpl(const QVariantMap& args) { // For now, let's just accept the phantomatic "32" button. It is also always explicit if (args["Button"].toInt() == 32) { if (args.contains("Type")) { triggerAction("SuspendSession", args["Type"]); } } } bool HandleButtonEvents::loadAction(const KConfigGroup& config) { // Read configs m_lidAction = config.readEntry("lidAction", 0); m_triggerLidActionWhenExternalMonitorPresent = config.readEntry("triggerLidActionWhenExternalMonitorPresent", false); m_powerButtonAction = config.readEntry("powerButtonAction", 0); checkOutputs(); return true; } int HandleButtonEvents::lidAction() const { return m_lidAction; } bool HandleButtonEvents::triggersLidAction() const { return m_triggerLidActionWhenExternalMonitorPresent || !m_externalMonitorPresent; } void HandleButtonEvents::powerOffButtonTriggered() { onButtonPressed(BackendInterface::PowerButton); } +void HandleButtonEvents::powerDownButtonTriggered() +{ + onButtonPressed(BackendInterface::PowerDownButton); +} + void HandleButtonEvents::suspendToDisk() { onButtonPressed(BackendInterface::HibernateButton); } void HandleButtonEvents::suspendToRam() { onButtonPressed(BackendInterface::SleepButton); } void HandleButtonEvents::checkOutputs() { if (!m_screenConfiguration) { qCWarning(POWERDEVIL) << "Handle button events action could not check for screen configuration"; return; } const bool old_triggersLidAction = triggersLidAction(); bool hasExternalMonitor = false; for(const KScreen::OutputPtr &output : m_screenConfiguration->outputs()) { if (output->isConnected() && output->isEnabled() && output->type() != KScreen::Output::Panel && output->type() != KScreen::Output::Unknown) { hasExternalMonitor = true; break; } } m_externalMonitorPresent = hasExternalMonitor; if (old_triggersLidAction != triggersLidAction()) { Q_EMIT triggersLidActionChanged(triggersLidAction()); // when the lid is closed but we don't suspend because of an external monitor but we then // unplug said monitor, re-trigger the lid action (Bug 379265) if (triggersLidAction() && backend()->isLidClosed()) { qCDebug(POWERDEVIL) << "External monitor that kept us from suspending is gone and lid is closed, re-triggering lid action"; onButtonPressed(BackendInterface::LidClose); } } } } } diff --git a/daemon/actions/bundled/handlebuttonevents.h b/daemon/actions/bundled/handlebuttonevents.h index 5a49ff4b..8c10bf6a 100644 --- a/daemon/actions/bundled/handlebuttonevents.h +++ b/daemon/actions/bundled/handlebuttonevents.h @@ -1,86 +1,87 @@ /*************************************************************************** * Copyright (C) 2010 by Dario Freddi * * Copyright (C) 2015 by Kai Uwe Broulik * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef POWERDEVIL_BUNDLEDACTIONS_HANDLEBUTTONEVENTS_H #define POWERDEVIL_BUNDLEDACTIONS_HANDLEBUTTONEVENTS_H #include #include #include namespace PowerDevil { namespace BundledActions { class HandleButtonEvents : public PowerDevil::Action { Q_OBJECT Q_DISABLE_COPY(HandleButtonEvents) Q_CLASSINFO("D-Bus Interface", "org.kde.Solid.PowerManagement.Actions.HandleButtonEvents") public: explicit HandleButtonEvents(QObject* parent); ~HandleButtonEvents() override; bool loadAction(const KConfigGroup& config) override; bool isSupported() override; Q_SIGNALS: void triggersLidActionChanged(bool triggers); protected: void triggerImpl(const QVariantMap& args) override; void onProfileUnload() override; void onWakeupFromIdle() override; void onIdleTimeout(int msec) override; void onProfileLoad() override; public Q_SLOTS: int lidAction() const; bool triggersLidAction() const; private Q_SLOTS: void onButtonPressed(PowerDevil::BackendInterface::ButtonType type); void powerOffButtonTriggered(); + void powerDownButtonTriggered(); void suspendToRam(); void suspendToDisk(); void checkOutputs(); private: void processAction(uint action); void triggerAction(const QString &action, const QVariant &type); KScreen::ConfigPtr m_screenConfiguration; uint m_lidAction = 0; bool m_triggerLidActionWhenExternalMonitorPresent = false; bool m_externalMonitorPresent = false; uint m_powerButtonAction = 0; uint m_sleepButtonAction = 1; uint m_hibernateButtonAction = 2; }; } } #endif // POWERDEVIL_BUNDLEDACTIONS_HANDLEBUTTONEVENTS_H diff --git a/daemon/powerdevilbackendinterface.h b/daemon/powerdevilbackendinterface.h index 544917f2..c35fed97 100644 --- a/daemon/powerdevilbackendinterface.h +++ b/daemon/powerdevilbackendinterface.h @@ -1,338 +1,339 @@ /*************************************************************************** * Copyright (C) 2010 by Dario Freddi * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #ifndef POWERDEVIL_BACKENDINTERFACE_H #define POWERDEVIL_BACKENDINTERFACE_H #include #include #include "powerdevilbrightnesslogic.h" class KJob; namespace PowerDevil { class Q_DECL_EXPORT BackendInterface : public QObject { Q_OBJECT Q_DISABLE_COPY(BackendInterface) public: explicit BackendInterface(QObject* parent = nullptr); ~BackendInterface() override; /** * This enum type defines the different states of the system battery. * * - NoBatteryState: No battery available * - Normal: The battery is at its normal charge level * - Warning: The battery is at its warning charge level * - Low: The battery is at its low charge level * - Critical: The battery is at its critical charge level */ enum BatteryState{ NoBatteryState, Normal, Warning, Low, Critical }; Q_ENUM(BatteryState) /** * This enum type defines the different states of the AC adapter. * * - UnknownAcAdapterState: The AC adapter has an unknown state * - Plugged: The AC adapter is plugged * - Unplugged: The AC adapter is unplugged */ enum AcAdapterState{ UnknownAcAdapterState, Plugged, Unplugged }; Q_ENUM(AcAdapterState) /** * This enum type defines the types of system button events. * * - UnknownButtonType: An unknown button + * - PowerDown: A power down pressed event, generally used to turn on or off the system. KWin emits on long power button presses. * - PowerButton: A power button pressed event, generally used to turn on or off the system * - SleepButton: A sleep button pressed event, generally used to make the system asleep * - LidOpen: A laptop lid open event * - LidClose: A laptop lid close event */ - enum ButtonType{ UnknownButtonType, PowerButton, SleepButton, LidOpen, LidClose, HibernateButton }; + enum ButtonType{ UnknownButtonType, PowerButton, PowerDownButton, SleepButton, LidOpen, LidClose, HibernateButton }; Q_ENUM(ButtonType) /** * This enum type defines the different suspend methods. * * - UnknownSuspendMethod: The name says it all * - Standby: Processes are stopped, some hardware is deactivated (ACPI S1) * - ToRam: Most devices are deactivated, only RAM is powered (ACPI S3) * - ToDisk: State of the machine is saved to disk, and it's powered down (ACPI S4) * - SuspendThenHibernate: Same as ToRam, but after a delay it switches to ToDisk */ enum SuspendMethod{ UnknownSuspendMethod = 0, Standby = 1, ToRam = 2, ToDisk = 4, HybridSuspend = 8, SuspendThenHibernate = 16 }; Q_ENUM(SuspendMethod) /** * This type stores an OR combination of SuspendMethod values. */ Q_DECLARE_FLAGS(SuspendMethods, SuspendMethod) /** * This enum defines the different types of brightness controls. * * - UnknownBrightnessControl: Unknown * - Screen: Brightness control for a monitor or laptop panel * - Keyboard: Brightness control for a keyboard backlight */ enum BrightnessControlType{ UnknownBrightnessControl = 0, Screen = 1, Keyboard = 2 }; Q_ENUM(BrightnessControlType) typedef QHash BrightnessControlsList; /** * This enum defines capabilities of the backend * * - SignalResumeFromSuspend: The backend is able to stream the @c resumeFromSuspend signal accurately */ enum Capability { NoCapabilities = 0, SignalResumeFromSuspend = 1 }; Q_ENUM(Capability) Q_DECLARE_FLAGS(Capabilities, Capability) /** * Initializes the backend. This function @b MUST be called before the backend is usable. Using * any method in BackendInterface without initializing it might lead to undefined behavior. The signal * @c backendReady or @c backendError will be streamed upon completion. * * @note Backend implementations @b MUST reimplement this function */ virtual void init() = 0; /** * @returns the capabilities of the backend * @see PowerDevil::BackendInterface::Capability */ Capabilities capabilities() const; /** * Retrieves the current state of the system battery. * * @return the current battery state * @see PowerDevil::BackendInterface::BatteryState */ BatteryState batteryState() const; /** * Retrieves the current estimated remaining time of the system batteries * * @return the current global estimated remaining time in milliseconds */ qulonglong batteryRemainingTime() const; /** * Retrieves the current state of the system AC adapter. * * @return the current AC adapter state * @see PowerDevil::BackendInterface::AcAdapterState */ AcAdapterState acAdapterState() const; /** * Retrieves the set of suspend methods supported by the system. * * @return the suspend methods supported by this system * @see PowerDevil::BackendInterface::SuspendMethod * @see PowerDevil::BackendInterface::SuspendMethods */ SuspendMethods supportedSuspendMethods() const; /** * Requests a suspend of the system. * * @param method the suspend method to use * @return the job handling the operation */ virtual KJob *suspend(SuspendMethod method) = 0; /** * Checks if brightness controls are enabled on this system. * * @return a list of the devices available to control */ BrightnessControlsList brightnessControlsAvailable() const; /** * Gets the device brightness value. * * @param device the name of the device that you would like to control * @return the brightness of the device, as an integer from 0 to brightnessValueMax */ virtual int brightness(BrightnessControlType type = Screen) const; /** * Gets the maximum device brightness value. * * @param device the name of the device that you would like to control * @return the maximum brightness of the device */ virtual int brightnessMax(BrightnessControlType type = Screen) const; /** * Gets the maximum device brightness step. * * @param device the name of the device that you would like to control * @return the maximum brightness of the device */ virtual int brightnessSteps(BrightnessControlType type = Screen) const; /** * @returns whether the lid is closed or not. */ bool isLidClosed() const; /** * @returns whether the a lid is present */ bool isLidPresent() const; void setLidPresent(bool present); /** * Sets the device brightness value. * * @param brightnessValue the desired device brightness, as an integer from 0 to brightnessValueMax * @param device the name of the device that you would like to control * @return true if the brightness change succeeded, false otherwise */ virtual void setBrightness(int value, BrightnessControlType type = Screen) = 0; /** * Should be called when the user presses a brightness key. * * @param type the type of the brightness key press * @return the new brightness value, or -1 if it could not be changed or determined * @see PowerDevil::BrightnessLogic::BrightnessKeyType */ virtual int brightnessKeyPressed(BrightnessLogic::BrightnessKeyType type, BrightnessControlType controlType = Screen) = 0; /** * Retrieves the capacities of the installed batteries in percentage. * * @returns A dictionary with the battery's capacity percentage mapped to the battery uuid. */ QHash capacities() const; Q_SIGNALS: /** * This signal is emitted when the AC adapter is plugged or unplugged. * * @param newState the new state of the AC adapter, it's one of the * type @see PowerDevil::BackendInterface::AcAdapterState */ void acAdapterStateChanged(PowerDevil::BackendInterface::AcAdapterState newState); /** * This signal is emitted when the system battery state changed. * * @param newState the new state of the system battery, it's one of the * type @see PowerDevil::BackendInterface::BatteryState */ void batteryStateChanged(PowerDevil::BackendInterface::BatteryState newState); /** * This signal is emitted when a button has been pressed. * * @param buttonType the pressed button type, it's one of the * type @see PowerDevil::BackendInterface::ButtonType */ void buttonPressed(PowerDevil::BackendInterface::ButtonType buttonType); /** * This signal is emitted when the brightness changes. * * @param brightnessInfo a copy of the current brightness information * @param type the device type */ void brightnessChanged(const BrightnessLogic::BrightnessInfo &brightnessInfo, BrightnessControlType type); /** * This signal is emitted when the estimated battery remaining time changes. * * @param time the new remaining time */ void batteryRemainingTimeChanged(qulonglong time); /** * This signal is emitted when the backend is ready to be used * * @see init */ void backendReady(); /** * This signal is emitted if the backend could not be initialized * * @param error Details about the error occurred * @see init */ void backendError(const QString &error); /** * This signal is emitted when the PC is resuming from suspension */ void resumeFromSuspend(); /** * This signal is emitted when the PC is about to suspend */ void aboutToSuspend(); /** * This signal is emitted when the laptop lid is closed or opened * * @param closed Whether the lid is now closed or not */ void lidClosedChanged(bool closed); protected: void setCapabilities(Capabilities capabilities); void onBrightnessChanged(BrightnessControlType device, int value, int valueMax); void setBatteryRemainingTime(qulonglong time); void setButtonPressed(PowerDevil::BackendInterface::ButtonType type); void setBatteryState(PowerDevil::BackendInterface::BatteryState state); void setAcAdapterState(PowerDevil::BackendInterface::AcAdapterState state); void setCapacityForBattery(const QString &batteryId, uint percent); void setBackendIsReady(BrightnessControlsList availableBrightnessControls, SuspendMethods supportedSuspendMethods); void setBackendHasError(const QString &errorDetails); // Steps logic int calculateNextStep(int value, int valueMax, BrightnessControlType controlType, BrightnessLogic::BrightnessKeyType type); private: class Private; Private * const d; friend class Core; }; } Q_DECLARE_OPERATORS_FOR_FLAGS(PowerDevil::BackendInterface::Capabilities) Q_DECLARE_OPERATORS_FOR_FLAGS(PowerDevil::BackendInterface::SuspendMethods) #endif // POWERDEVIL_BACKENDINTERFACE_H diff --git a/daemon/powerdevilprofilegenerator.cpp b/daemon/powerdevilprofilegenerator.cpp index 0cc0fa73..744083b7 100644 --- a/daemon/powerdevilprofilegenerator.cpp +++ b/daemon/powerdevilprofilegenerator.cpp @@ -1,158 +1,147 @@ /*************************************************************************** * Copyright (C) 2010 by Dario Freddi * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program 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 General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "powerdevilprofilegenerator.h" #include #include #include #include #include namespace PowerDevil { void ProfileGenerator::generateProfiles(bool toRam, bool toDisk) { // Change critical action if default (hibernate) is unavailable if (!toDisk) { if (!toRam) { PowerDevilSettings::setBatteryCriticalAction(0); } else { PowerDevilSettings::setBatteryCriticalAction(1); } PowerDevilSettings::self()->save(); } // Ok, let's get our config file. KSharedConfigPtr profilesConfig = KSharedConfig::openConfig("powermanagementprofilesrc", KConfig::SimpleConfig); // And clear it const QStringList groupList = profilesConfig->groupList(); for (const QString &group : groupList) { // Don't delete activity-specific settings if (group != "Activities") { profilesConfig->deleteGroup(group); } } // Let's start: AC profile before anything else KConfigGroup acProfile(profilesConfig, "AC"); acProfile.writeEntry("icon", "battery-charging"); - const bool mobile = !qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_MOBILE"); - const Modes defaultPowerButtonAction = mobile ? LockScreenMode : LogoutDialogMode; - // We want to dim the screen after a while, definitely { KConfigGroup dimDisplay(&acProfile, "DimDisplay"); dimDisplay.writeEntry< int >("idleTime", 300000); } - // Show the dialog when power button is pressed and suspend on suspend button pressed and lid closed (if supported) + + auto initLid = [toRam](KConfigGroup &profile) { - KConfigGroup handleButtonEvents(&acProfile, "HandleButtonEvents"); + const bool mobile = !qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_MOBILE"); + const Modes defaultPowerButtonAction = mobile ? ToRamMode : LogoutDialogMode; + KConfigGroup handleButtonEvents(&profile, "HandleButtonEvents"); handleButtonEvents.writeEntry< uint >("powerButtonAction", defaultPowerButtonAction); - + handleButtonEvents.writeEntry< uint >("powerDownAction", LogoutDialogMode); if (toRam) { handleButtonEvents.writeEntry< uint >("lidAction", ToRamMode); } else { handleButtonEvents.writeEntry< uint >("lidAction", TurnOffScreenMode); } - } + }; + + // Show the dialog when power button is pressed and suspend on suspend button pressed and lid closed (if supported) + initLid(acProfile); // And we also want to turn off the screen after another while { KConfigGroup dpmsControl(&acProfile, "DPMSControl"); dpmsControl.writeEntry< uint >("idleTime", 600); } // Powersave KConfigGroup batteryProfile(profilesConfig, "Battery"); batteryProfile.writeEntry("icon", "battery-060"); // We want to dim the screen after a while, definitely { KConfigGroup dimDisplay(&batteryProfile, "DimDisplay"); dimDisplay.writeEntry< int >("idleTime", 120000); } // Show the dialog when power button is pressed and suspend on suspend button pressed and lid closed (if supported) - { - KConfigGroup handleButtonEvents(&batteryProfile, "HandleButtonEvents"); - handleButtonEvents.writeEntry< uint >("powerButtonAction", defaultPowerButtonAction); - if (toRam) { - handleButtonEvents.writeEntry< uint >("lidAction", ToRamMode); - } else { - handleButtonEvents.writeEntry< uint >("lidAction", TurnOffScreenMode); - } - } + initLid(batteryProfile); + // We want to turn off the screen after another while { KConfigGroup dpmsControl(&batteryProfile, "DPMSControl"); dpmsControl.writeEntry< uint >("idleTime", 300); } // Last but not least, we want to suspend after a rather long period of inactivity if (toRam) { KConfigGroup suspendSession(&batteryProfile, "SuspendSession"); suspendSession.writeEntry< uint >("idleTime", 600000); suspendSession.writeEntry< uint >("suspendType", ToRamMode); } // Ok, now for aggressive powersave KConfigGroup lowBatteryProfile(profilesConfig, "LowBattery"); lowBatteryProfile.writeEntry("icon", "battery-low"); // Less brightness. { KConfigGroup brightnessControl(&lowBatteryProfile, "BrightnessControl"); brightnessControl.writeEntry< int >("value", 30); } // We want to dim the screen after a while, definitely { KConfigGroup dimDisplay(&lowBatteryProfile, "DimDisplay"); dimDisplay.writeEntry< int >("idleTime", 60000); } // Show the dialog when power button is pressed and suspend on suspend button pressed and lid closed (if supported) - { - KConfigGroup handleButtonEvents(&lowBatteryProfile, "HandleButtonEvents"); - handleButtonEvents.writeEntry< uint >("powerButtonAction", defaultPowerButtonAction); - if (toRam) { - handleButtonEvents.writeEntry< uint >("lidAction", ToRamMode); - } else { - handleButtonEvents.writeEntry< uint >("lidAction", TurnOffScreenMode); - } - } + initLid(lowBatteryProfile); + // We want to turn off the screen after another while { KConfigGroup dpmsControl(&lowBatteryProfile, "DPMSControl"); dpmsControl.writeEntry< uint >("idleTime", 120); } // Last but not least, we want to suspend after a rather long period of inactivity if (toRam) { KConfigGroup suspendSession(&lowBatteryProfile, "SuspendSession"); suspendSession.writeEntry< uint >("idleTime", 300000); suspendSession.writeEntry< uint >("suspendType", ToRamMode); } // Save and be happy profilesConfig->sync(); } }