diff --git a/daemon/actions/bundled/handlebuttoneventsconfig.cpp b/daemon/actions/bundled/handlebuttoneventsconfig.cpp index 08368b87..ed8cebb2 100644 --- a/daemon/actions/bundled/handlebuttoneventsconfig.cpp +++ b/daemon/actions/bundled/handlebuttoneventsconfig.cpp @@ -1,178 +1,178 @@ /*************************************************************************** * 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 "handlebuttoneventsconfig.h" #include "suspendsession.h" #include "upower_interface.h" #include "powerdevilpowermanagement.h" #include #include #include #include #include #include K_PLUGIN_FACTORY(PowerDevilSuspendSessionConfigFactory, registerPlugin(); ) namespace PowerDevil { namespace BundledActions { HandleButtonEventsConfig::HandleButtonEventsConfig(QObject* parent, const QVariantList& ) : ActionConfig(parent) { } HandleButtonEventsConfig::~HandleButtonEventsConfig() { } void HandleButtonEventsConfig::save() { if (m_lidCloseCombo) { configGroup().writeEntry("lidAction", m_lidCloseCombo->itemData(m_lidCloseCombo->currentIndex()).toUInt()); } if (m_triggerLidActionWhenExternalMonitorPresent) { configGroup().writeEntry("triggerLidActionWhenExternalMonitorPresent", m_triggerLidActionWhenExternalMonitorPresent->isChecked()); } if (m_powerButtonCombo) { configGroup().writeEntry("powerButtonAction", m_powerButtonCombo->itemData(m_powerButtonCombo->currentIndex()).toUInt()); } configGroup().sync(); } void HandleButtonEventsConfig::load() { configGroup().config()->reparseConfiguration(); if (m_lidCloseCombo) { m_lidCloseCombo->setCurrentIndex(m_lidCloseCombo->findData(QVariant::fromValue(configGroup().readEntry("lidAction", 0)))); } if (m_triggerLidActionWhenExternalMonitorPresent) { m_triggerLidActionWhenExternalMonitorPresent->setChecked(configGroup().readEntry("triggerLidActionWhenExternalMonitorPresent", false)); } if (m_powerButtonCombo) { m_powerButtonCombo->setCurrentIndex(m_powerButtonCombo->findData(QVariant::fromValue(configGroup().readEntry("powerButtonAction", 0)))); } } QList< QPair< QString, QWidget* > > HandleButtonEventsConfig::buildUi() { // Create the boxes m_lidCloseCombo = new QComboBox; m_triggerLidActionWhenExternalMonitorPresent = new QCheckBox( i18nc("Execute action on lid close even when external monitor is connected", "Even when an external monitor is connected") ); m_powerButtonCombo = new QComboBox; // Fill the boxes with options! { QList boxes; boxes << m_lidCloseCombo << m_powerButtonCombo; Q_FOREACH (QComboBox *box, boxes) { box->addItem(QIcon::fromTheme("dialog-cancel"), i18n("Do nothing"), (uint)SuspendSession::None); if (PowerManagement::instance()->canSuspend()) { - box->addItem(QIcon::fromTheme("system-suspend"), i18n("Suspend"), (uint)SuspendSession::ToRamMode); + box->addItem(QIcon::fromTheme("system-suspend"), i18nc("Suspend to RAM", "Sleep"), (uint)SuspendSession::ToRamMode); } if (PowerManagement::instance()->canHibernate()) { box->addItem(QIcon::fromTheme("system-suspend-hibernate"), i18n("Hibernate"), (uint)SuspendSession::ToDiskMode); } if (PowerManagement::instance()->canHybridSuspend()) { - box->addItem(QIcon::fromTheme("system-suspend-hybrid"), i18n("Hybrid suspend"), (uint)SuspendSession::SuspendHybridMode); + box->addItem(QIcon::fromTheme("system-suspend-hybrid"), i18n("Hybrid sleep"), (uint)SuspendSession::SuspendHybridMode); } box->addItem(QIcon::fromTheme("system-shutdown"), i18n("Shut down"), (uint)SuspendSession::ShutdownMode); box->addItem(QIcon::fromTheme("system-lock-screen"), i18n("Lock screen"), (uint)SuspendSession::LockScreenMode); if (box != m_lidCloseCombo) { box->addItem(QIcon::fromTheme("system-log-out"), i18n("Prompt log out dialog"), (uint)SuspendSession::LogoutDialogMode); } box->addItem(QIcon::fromTheme("preferences-desktop-screensaver"), i18n("Turn off screen"), (uint)SuspendSession::TurnOffScreenMode); } } connect(m_lidCloseCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged())); connect(m_triggerLidActionWhenExternalMonitorPresent, SIGNAL(stateChanged(int)), this, SLOT(setChanged())); connect(m_powerButtonCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged())); bool lidFound = false; bool powerFound = true; // HACK This needs proper API!! // get a list of all devices that are Buttons /* Q_FOREACH (Solid::Device device, Solid::Device::listFromType(Solid::DeviceInterface::Button, QString())) { Solid::Button *button = device.as(); if (button->type() == Solid::Button::LidButton) { lidFound = true; } else if (button->type() == Solid::Button::PowerButton) { powerFound = true; } }*/ auto m_upowerInterface = new OrgFreedesktopUPowerInterface("org.freedesktop.UPower", "/org/freedesktop/UPower", QDBusConnection::systemBus(), this); lidFound = m_upowerInterface->lidIsPresent(); QList< QPair< QString, QWidget* > > retlist; if (lidFound) { retlist.append(qMakePair(i18n("When laptop lid closed"), m_lidCloseCombo)); // an empty label will make it treat the widget as title checkbox and left-align it retlist.append(qMakePair(QLatin1Literal("NONE"), m_triggerLidActionWhenExternalMonitorPresent)); } else { m_lidCloseCombo->deleteLater(); m_lidCloseCombo = nullptr; m_triggerLidActionWhenExternalMonitorPresent->deleteLater(); m_triggerLidActionWhenExternalMonitorPresent = nullptr; } if (powerFound) { retlist.append(qMakePair< QString, QWidget* >(i18n("When power button pressed"), m_powerButtonCombo)); } else { m_powerButtonCombo->deleteLater(); m_powerButtonCombo = nullptr; } // unified width for the comboboxes int comboBoxMaxWidth = 300; if (m_lidCloseCombo) { comboBoxMaxWidth = qMax(comboBoxMaxWidth, m_lidCloseCombo->sizeHint().width()); } if (m_powerButtonCombo) { comboBoxMaxWidth = qMax(comboBoxMaxWidth, m_powerButtonCombo->sizeHint().width()); } if (m_lidCloseCombo) { m_lidCloseCombo->setMinimumWidth(300); m_lidCloseCombo->setMaximumWidth(comboBoxMaxWidth); } if (m_powerButtonCombo) { m_powerButtonCombo->setMinimumWidth(300); m_powerButtonCombo->setMaximumWidth(comboBoxMaxWidth); } return retlist; } } } #include "handlebuttoneventsconfig.moc" diff --git a/daemon/actions/bundled/suspendsessionconfig.cpp b/daemon/actions/bundled/suspendsessionconfig.cpp index e2f540ea..024dff4e 100644 --- a/daemon/actions/bundled/suspendsessionconfig.cpp +++ b/daemon/actions/bundled/suspendsessionconfig.cpp @@ -1,111 +1,111 @@ /*************************************************************************** * 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 "suspendsessionconfig.h" #include "powerdevilpowermanagement.h" #include #include #include #include #include #include #include #include #include "suspendsession.h" K_PLUGIN_FACTORY(PowerDevilSuspendSessionConfigFactory, registerPlugin(); ) namespace PowerDevil { namespace BundledActions { SuspendSessionConfig::SuspendSessionConfig(QObject* parent, const QVariantList&) : ActionConfig(parent) { } SuspendSessionConfig::~SuspendSessionConfig() { } void SuspendSessionConfig::save() { configGroup().writeEntry< uint >("suspendType", m_comboBox->itemData(m_comboBox->currentIndex()).toUInt()); configGroup().writeEntry("idleTime", m_idleTime->value() * 60 * 1000); configGroup().sync(); } void SuspendSessionConfig::load() { configGroup().config()->reparseConfiguration(); uint suspendType = configGroup().readEntry< uint >("suspendType", 0); m_comboBox->setCurrentIndex(m_comboBox->findData(suspendType)); m_idleTime->setValue((configGroup().readEntry("idleTime", 600000) / 60) / 1000); } QList< QPair< QString, QWidget* > > SuspendSessionConfig::buildUi() { QWidget *tempWidget = new QWidget; QHBoxLayout *hlay = new QHBoxLayout; m_comboBox = new KComboBox; m_idleTime = new QSpinBox; m_idleTime->setMaximumWidth(150); m_idleTime->setMinimum(1); m_idleTime->setMaximum(360); m_idleTime->setValue(0); m_idleTime->setSuffix(i18n(" min")); if (PowerManagement::instance()->canSuspend()) { - m_comboBox->addItem(QIcon::fromTheme("system-suspend"), i18n("Suspend"), (uint)SuspendSession::ToRamMode); + m_comboBox->addItem(QIcon::fromTheme("system-suspend"), i18nc("Suspend to RAM", "Sleep"), (uint)SuspendSession::ToRamMode); } if (PowerManagement::instance()->canHibernate()) { m_comboBox->addItem(QIcon::fromTheme("system-suspend-hibernate"), i18n("Hibernate"), (uint)SuspendSession::ToDiskMode); } 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); m_comboBox->addItem(QIcon::fromTheme("system-lock-screen"), i18n("Lock screen"), (uint)SuspendSession::LockScreenMode); hlay->addWidget(m_idleTime); hlay->addWidget(m_comboBox); hlay->addStretch(); tempWidget->setLayout(hlay); QList< QPair< QString, QWidget* > > retlist; retlist.append(qMakePair< QString, QWidget* >(i18n("After"), tempWidget)); connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged())); connect(m_idleTime, SIGNAL(valueChanged(int)), this, SLOT(setChanged())); return retlist; } } } #include "suspendsessionconfig.moc" diff --git a/doc/kcm/index.docbook b/doc/kcm/index.docbook index f9815b47..157efe38 100644 --- a/doc/kcm/index.docbook +++ b/doc/kcm/index.docbook @@ -1,295 +1,295 @@ ]>
Power Management &Dario.Freddi;&Dario.Freddi.mail; 2016-08-26 &plasma; 5.7 Plasma System Settings powerdevil power management laptop power PowerDevil, a Power Management Daemon This module is a configuration tool for managing Power Management in &plasma;. It is a configurator for the PowerDevil daemon, that you can start or stop from the Background Services module in &systemsettings;. Through this module, you can define your computer's behavior in various situations, allowing you to save as much energy as possible. Powerdevil works with Solid only and it's integrated in your desktop. You won't even notice it is running, apart from notifications. Moreover, Powerdevil checks your system capabilities first, so you'll see only options available for your system in this module. Note that PowerDevil does not poll your system. This means that it will not waste energy while trying to save it, as some other power managers do. Energy Saving Settings This page shows the actual energy saving settings. If a battery is detected you have three tabs with different settings for On AC Power, On Battery and On Low Battery profiles. Energy Saving Settings Energy Saving Settings Energy Saving Settings There are a lot of options you can configure for each profile: Screen brightness Sets the screen's brightness using a slider. Dim screen If checked, the display will be progressively dimmed, until reaching brightness 0, in the amount of time you specify in the spin box. Screen Energy Saving Here you can set the timeout for switch off in the spin box. Suspend session Suspends the session after the selected time to the status -Suspend, Hibernate, +Sleep, Hibernate, Shutdown or Lock screen. Button events handling Select actions to perform whenever the laptop lid is closed or a button is pressed. Run Script Activate this option to run a custom script when a profile is loaded, unloaded or after a given amount of time. Wireless power saving Activate this option to set individual actions for Wi-Fi, Mobile broadband or Bluetooth connections. Activity Settings Here you can configure the Power Management settings per activity. The settings for each activity can be configured on its own tab. Activity Settings Activity Settings Activity Settings Don't use special settings Use the settings defined on Energy Saving page. Define a special behavior -If this option is chosen, a special behavior for activity can be chosen. If this is a presentation activity, you can check the Never shutdown the screen and Never suspend or shutdown the computer boxes. It is also possible to define the time interval for the computer to switch to a suspension mode for the power saving activities. +If this option is chosen, a special behavior for activity can be chosen. If this is a presentation activity, you can check the Never shutdown the screen and Never shutdown the computer or let it go to sleep boxes. It is also possible to define the time interval for the computer to switch to a suspension mode for the power saving activities. Use separate settings (advanced users only) This option allows users to choose the detail power saving settings for a separate activity. The settings are similar to the settings from the Energy Saving page. Advanced Settings Advanced Settings Advanced Settings Advanced Settings Battery levels These items are only displayed if a battery is detected. Low level Here you can set the percentage after which the battery will be considered low. Critical level Here you can set the percentage after which the battery will be considered at critical level. At critical level Defines the action that will be done when battery reaches the critical level. Peripheral devices Defines the low level for peripheral devices ⪚ a wireless mouse. Configure Notifications If you want a deeper control over your notifications, you can refine them by clicking this button. PowerDevil Runner PowerDevil can be manually controlled through &krunner; (&Alt;F2). This makes changing profile, brightness, governor and more much easier and faster. The runner has various keywords you can enter to access its functions Runner Keywords Here comes a list of keywords you can enter in &krunner; to perform PowerDevil related actions. power profile You can manually choose a profile using this keyword. All available profiles will be shown in form of &krunner; matches. screen brightness or dim screen You can control screen brightness through this keyword. In this form, some &krunner; matches that let you do some common actions will be shown. If you enter a value after the keyword (⪚: Screen Brightness 50), the brightness will be set to that value. suspend, sleep, hibernate, to ram or to disk You can set your computer into a low power mode through these keywords. Available methods will be shown as &krunner; matches.
diff --git a/kcmodule/activities/activityWidget.ui b/kcmodule/activities/activityWidget.ui index e17aaeb2..7ab376b9 100644 --- a/kcmodule/activities/activityWidget.ui +++ b/kcmodule/activities/activityWidget.ui @@ -1,185 +1,185 @@ ActivityWidget 0 0 676 474 Don't use special settings true Act like false Qt::Horizontal 40 20 Define a special behavior 30 Never shutdown the screen - Never suspend or shutdown the computer + Never shutdown the computer or let it go to sleep 10 Always after min 1 360 Qt::Horizontal 40 20 Use separate settings (advanced users only) 30 Qt::Vertical 20 268 actLikeRadio toggled(bool) actLikeComboBox setEnabled(bool) 44 66 133 66 diff --git a/kcmodule/activities/activitywidget.cpp b/kcmodule/activities/activitywidget.cpp index 43c0b144..64d4a373 100644 --- a/kcmodule/activities/activitywidget.cpp +++ b/kcmodule/activities/activitywidget.cpp @@ -1,200 +1,200 @@ /*************************************************************************** * Copyright (C) 2011 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 "activitywidget.h" #include "ui_activityWidget.h" #include "../daemon/actions/bundled/suspendsession.h" #include "powerdevilpowermanagement.h" #include #include #include #include #include #include ActivityWidget::ActivityWidget(const QString& activity, QWidget* parent) : QWidget(parent) , m_ui(new Ui::ActivityWidget) , m_profilesConfig(KSharedConfig::openConfig("powermanagementprofilesrc", KConfig::SimpleConfig | KConfig::CascadeConfig)) , m_activity(activity) , m_activityConsumer(new KActivities::Consumer(this)) , m_actionEditWidget(new ActionEditWidget(QString("Activities/%1/SeparateSettings").arg(activity))) { m_ui->setupUi(this); m_ui->separateSettingsLayout->addWidget(m_actionEditWidget); for (int i = 0; i < m_ui->specialBehaviorLayout->count(); ++i) { QWidget *widget = m_ui->specialBehaviorLayout->itemAt(i)->widget(); if (widget) { widget->setVisible(false); connect(m_ui->specialBehaviorRadio, SIGNAL(toggled(bool)), widget, SLOT(setVisible(bool))); } else { QLayout *layout = m_ui->specialBehaviorLayout->itemAt(i)->layout(); if (layout) { for (int j = 0; j < layout->count(); ++j) { QWidget *widget = layout->itemAt(j)->widget(); if (widget) { widget->setVisible(false); connect(m_ui->specialBehaviorRadio, SIGNAL(toggled(bool)), widget, SLOT(setVisible(bool))); } } } } } m_actionEditWidget->setVisible(false); m_actionEditWidget->load(); connect(m_ui->separateSettingsRadio, SIGNAL(toggled(bool)), m_actionEditWidget, SLOT(setVisible(bool))); connect(m_ui->actLikeRadio, SIGNAL(toggled(bool)), this, SLOT(setChanged())); connect(m_ui->noSettingsRadio, SIGNAL(toggled(bool)), this, SLOT(setChanged())); connect(m_ui->separateSettingsRadio, SIGNAL(toggled(bool)), this, SLOT(setChanged())); connect(m_ui->specialBehaviorRadio, SIGNAL(toggled(bool)), this, SLOT(setChanged())); connect(m_ui->actLikeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged())); connect(m_ui->alwaysActionBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged())); connect(m_ui->alwaysAfterSpin, SIGNAL(valueChanged(int)), this, SLOT(setChanged())); connect(m_actionEditWidget, SIGNAL(changed(bool)), this, SIGNAL(changed(bool))); } ActivityWidget::~ActivityWidget() { } void ActivityWidget::load() { KConfigGroup activitiesGroup(m_profilesConfig, "Activities"); KConfigGroup config = activitiesGroup.group(m_activity); using namespace PowerDevil::BundledActions; if (PowerDevil::PowerManagement::instance()->canSuspend()) { m_ui->alwaysActionBox->addItem(QIcon::fromTheme("system-suspend"), - i18n("Suspend"), (uint)SuspendSession::ToRamMode); + i18nc("Suspend to RAM", "Sleep"), (uint)SuspendSession::ToRamMode); } if (PowerDevil::PowerManagement::instance()->canHibernate()) { m_ui->alwaysActionBox->addItem(QIcon::fromTheme("system-suspend-hibernate"), i18n("Hibernate"), (uint)SuspendSession::ToDiskMode); } m_ui->alwaysActionBox->addItem(QIcon::fromTheme("system-shutdown"), i18n("Shut down"), (uint)SuspendSession::ShutdownMode); m_ui->actLikeComboBox->clear(); m_ui->actLikeComboBox->addItem(QIcon::fromTheme("battery-charging"), i18n("PC running on AC power"), "AC"); m_ui->actLikeComboBox->addItem(QIcon::fromTheme("battery-060"), i18n("PC running on battery power"), "Battery"); m_ui->actLikeComboBox->addItem(QIcon::fromTheme("battery-low"), i18n("PC running on low battery"), "LowBattery"); bool hasBattery = false; Q_FOREACH (const Solid::Device &device, Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString())) { const Solid::Battery *b = qobject_cast (device.asDeviceInterface(Solid::DeviceInterface::Battery)); if (b->type() == Solid::Battery::PrimaryBattery || b->type() == Solid::Battery::UpsBattery) { hasBattery = false; break; } } m_ui->actLikeRadio->setVisible(hasBattery); m_ui->actLikeComboBox->setVisible(hasBattery); Q_FOREACH (const QString &activity, m_activityConsumer->activities()) { if (activity == m_activity) { continue; } if (activitiesGroup.group(activity).readEntry("mode", "None") == "None" || activitiesGroup.group(activity).readEntry("mode", "None") == "ActLike") { continue; } KActivities::Info *info = new KActivities::Info(activity, this); QString icon = info->icon(); QString name = i18nc("This is meant to be: Act like activity %1", "Activity \"%1\"", info->name()); m_ui->actLikeComboBox->addItem(QIcon::fromTheme(icon), name, activity); } // Proper loading routine if (config.readEntry("mode", QString()) == "ActLike") { m_ui->actLikeRadio->setChecked(true); m_ui->actLikeComboBox->setCurrentIndex(m_ui->actLikeComboBox->findData(config.readEntry("actLike", QString()))); } else if (config.readEntry("mode", QString()) == "SpecialBehavior") { m_ui->specialBehaviorRadio->setChecked(true); KConfigGroup behaviorGroup = config.group("SpecialBehavior"); m_ui->noShutdownPCBox->setChecked(behaviorGroup.readEntry("noSuspend", false)); m_ui->noShutdownScreenBox->setChecked(behaviorGroup.readEntry("noScreenManagement", false)); m_ui->alwaysBox->setChecked(behaviorGroup.readEntry("performAction", false)); KConfigGroup actionConfig = behaviorGroup.group("ActionConfig"); m_ui->alwaysActionBox->setCurrentIndex(m_ui->alwaysActionBox->findData(actionConfig.readEntry("suspendType", 0))); m_ui->alwaysAfterSpin->setValue(actionConfig.readEntry("idleTime", 600000) / 60 / 1000); } else if (config.readEntry("mode", QString()) == "SeparateSettings") { m_ui->separateSettingsRadio->setChecked(true); m_actionEditWidget->load(); } } void ActivityWidget::save() { KConfigGroup activitiesGroup(m_profilesConfig, "Activities"); KConfigGroup config = activitiesGroup.group(m_activity); if (m_ui->actLikeRadio->isChecked()) { config.writeEntry("mode", "ActLike"); config.writeEntry("actLike", m_ui->actLikeComboBox->itemData(m_ui->actLikeComboBox->currentIndex()).toString()); } else if (m_ui->specialBehaviorRadio->isChecked()) { config.writeEntry("mode", "SpecialBehavior"); KConfigGroup behaviorGroup = config.group("SpecialBehavior"); behaviorGroup.writeEntry("noSuspend", m_ui->noShutdownPCBox->isChecked()); behaviorGroup.writeEntry("noScreenManagement", m_ui->noShutdownScreenBox->isChecked()); behaviorGroup.writeEntry("performAction", m_ui->alwaysBox->isChecked()); KConfigGroup actionConfig = behaviorGroup.group("ActionConfig"); actionConfig.writeEntry("suspendType", m_ui->alwaysActionBox->itemData(m_ui->alwaysActionBox->currentIndex())); actionConfig.writeEntry("idleTime", m_ui->alwaysAfterSpin->value() * 60 * 1000); actionConfig.sync(); behaviorGroup.sync(); } else if (m_ui->separateSettingsRadio->isChecked()) { config.writeEntry("mode", "SeparateSettings"); m_actionEditWidget->save(); } else { config.writeEntry("mode", "None"); } config.sync(); } void ActivityWidget::setChanged() { Q_EMIT changed(true); } diff --git a/kcmodule/global/GeneralPage.cpp b/kcmodule/global/GeneralPage.cpp index c699b924..858441d1 100644 --- a/kcmodule/global/GeneralPage.cpp +++ b/kcmodule/global/GeneralPage.cpp @@ -1,214 +1,214 @@ /*************************************************************************** * Copyright (C) 2008 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 "GeneralPage.h" #include "ErrorOverlay.h" #include "PowerDevilSettings.h" #include "actions/bundled/suspendsession.h" #include "powerdevilpowermanagement.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include K_PLUGIN_FACTORY(PowerDevilGeneralKCMFactory, registerPlugin(); ) GeneralPage::GeneralPage(QWidget *parent, const QVariantList &args) : KCModule(nullptr, parent, args) { setButtons(Apply | Help); // KAboutData *about = // new KAboutData("powerdevilglobalconfig", "powerdevilglobalconfig", ki18n("Global Power Management Configuration"), // "", ki18n("A global power management configurator for KDE Power Management System"), // KAboutData::License_GPL, ki18n("(c), 2010 Dario Freddi"), // ki18n("From this module, you can configure the main Power Management daemon, assign profiles to " // "states, and do some advanced fine tuning on battery handling")); // // about->addAuthor(ki18n("Dario Freddi"), ki18n("Maintainer") , "drf@kde.org", // "http://drfav.wordpress.com"); // // setAboutData(about); setupUi(this); fillUi(); QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.kde.Solid.PowerManagement", QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, this); connect(watcher, SIGNAL(serviceRegistered(QString)), this, SLOT(onServiceRegistered(QString))); connect(watcher, SIGNAL(serviceUnregistered(QString)), this, SLOT(onServiceUnregistered(QString))); if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.Solid.PowerManagement")) { onServiceRegistered("org.kde.Solid.PowerManagement"); } else { onServiceUnregistered("org.kde.Solid.PowerManagement"); } } GeneralPage::~GeneralPage() { } void GeneralPage::fillUi() { bool hasPowerSupplyBattery = false; bool hasPeripheralBattery = false; Q_FOREACH (const Solid::Device &device, Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString())) { const Solid::Battery *b = qobject_cast (device.asDeviceInterface(Solid::DeviceInterface::Battery)); if (b->isPowerSupply()) { hasPowerSupplyBattery = true; } else { hasPeripheralBattery = true; } } BatteryCriticalCombo->addItem(QIcon::fromTheme("dialog-cancel"), i18n("Do nothing"), PowerDevil::BundledActions::SuspendSession::None); if (PowerDevil::PowerManagement::instance()->canSuspend()) { - BatteryCriticalCombo->addItem(QIcon::fromTheme("system-suspend"), i18n("Suspend"), PowerDevil::BundledActions::SuspendSession::ToRamMode); + BatteryCriticalCombo->addItem(QIcon::fromTheme("system-suspend"), i18nc("Suspend to RAM", "Sleep"), PowerDevil::BundledActions::SuspendSession::ToRamMode); } 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); notificationsButton->setIcon(QIcon::fromTheme("preferences-desktop-notification")); // modified fields... connect(notificationsButton, SIGNAL(clicked()), SLOT(configureNotifications())); connect(lowSpin, SIGNAL(valueChanged(int)), SLOT(changed())); connect(criticalSpin, SIGNAL(valueChanged(int)), SLOT(changed())); connect(lowPeripheralSpin, SIGNAL(valueChanged(int)), SLOT(changed())); connect(BatteryCriticalCombo, SIGNAL(currentIndexChanged(int)), SLOT(changed())); connect(pausePlayersCheckBox, SIGNAL(stateChanged(int)), SLOT(changed())); if (!hasPowerSupplyBattery) { BatteryCriticalLabel->hide(); BatteryCriticalCombo->hide(); lowLabel->hide(); lowSpin->hide(); criticalLabel->hide(); criticalSpin->hide(); } if (!hasPeripheralBattery) { lowPeripheralLabel->hide(); lowPeripheralSpin->hide(); } if (!hasPowerSupplyBattery && !hasPeripheralBattery) { batteryLevelsLabel->hide(); } } void GeneralPage::load() { lowSpin->setValue(PowerDevilSettings::batteryLowLevel()); criticalSpin->setValue(PowerDevilSettings::batteryCriticalLevel()); lowPeripheralSpin->setValue(PowerDevilSettings::peripheralBatteryLowLevel()); BatteryCriticalCombo->setCurrentIndex(BatteryCriticalCombo->findData(PowerDevilSettings::batteryCriticalAction())); pausePlayersCheckBox->setChecked(PowerDevilSettings::pausePlayersOnSuspend()); } void GeneralPage::configureNotifications() { KNotifyConfigWidget::configure(this, "powerdevil"); } void GeneralPage::save() { PowerDevilSettings::setBatteryLowLevel(lowSpin->value()); PowerDevilSettings::setBatteryCriticalLevel(criticalSpin->value()); PowerDevilSettings::setPeripheralBatteryLowLevel(lowPeripheralSpin->value()); PowerDevilSettings::setBatteryCriticalAction(BatteryCriticalCombo->itemData(BatteryCriticalCombo->currentIndex()).toInt()); PowerDevilSettings::setPausePlayersOnSuspend(pausePlayersCheckBox->checkState() == Qt::Checked); PowerDevilSettings::self()->save(); // Notify Daemon QDBusMessage call = QDBusMessage::createMethodCall("org.kde.Solid.PowerManagement", "/org/kde/Solid/PowerManagement", "org.kde.Solid.PowerManagement", "refreshStatus"); // Perform call QDBusConnection::sessionBus().asyncCall(call); // And now we are set with no change Q_EMIT changed(false); } void GeneralPage::defaults() { KCModule::defaults(); } void GeneralPage::onServiceRegistered(const QString& service) { Q_UNUSED(service); if (m_errorOverlay) { m_errorOverlay->deleteLater(); m_errorOverlay = nullptr; } } void GeneralPage::onServiceUnregistered(const QString& service) { Q_UNUSED(service); if (m_errorOverlay) { m_errorOverlay->deleteLater(); } m_errorOverlay = new ErrorOverlay(this, i18n("The Power Management Service appears not to be running.\n" "This can be solved by starting or scheduling it inside \"Startup and Shutdown\""), this); } #include "GeneralPage.moc"