[plasma/powerdevil] /: Drop most per-activity power settings
Nicolas Fella
null at kde.org
Tue Apr 4 20:01:41 BST 2023
Git commit 121df4cd76464aa987006e42a29672b412e15435 by Nicolas Fella.
Committed on 04/04/2023 at 18:59.
Pushed by nicolasfella into branch 'master'.
Drop most per-activity power settings
Currently there's four different modes for per-activity power settings
1) No special settings
2) "Act like" something else, where something else can be Battery, AC, or another activity. The UI
for this mode has been broken due to a bug for seven years (https://invent.kde.org/plasma/powerdevil/-/commit/1cf565eeb3ddc98a2df0066b4e5258aaf1e25008)
Apparently nobody noticed or missed it
3) Define a special behavior, like inhibiting screen power management or suspend. Usually this shouldn't
be needed, because applications where either of them is relevant should request inhibiting those themselves.
Alternatively it is possible to manually inhibit power management from the applet. I can see how this is potentially
useful though
4) Completely custom per-activity settings. This is basically the regular settings, applied to a specific activity only.
This makes the UI very complex, and appears very niche without apparent tangible use cases
This change removes 4) due to the ratio of code and UI complexity to usefulness
2) is removed too, given it has been broken long enough
Fixes https://invent.kde.org/plasma/plasma-desktop/-/issues/60
M +18 -45 daemon/powerdevilcore.cpp
M +0 -8 doc/kcm/index.docbook
M +1 -63 kcmodule/activities/activityWidget.ui
M +5 -71 kcmodule/activities/activitywidget.cpp
M +0 -2 kcmodule/activities/activitywidget.h
https://invent.kde.org/plasma/powerdevil/commit/121df4cd76464aa987006e42a29672b412e15435
diff --git a/daemon/powerdevilcore.cpp b/daemon/powerdevilcore.cpp
index 559bd7942..5393f753c 100644
--- a/daemon/powerdevilcore.cpp
+++ b/daemon/powerdevilcore.cpp
@@ -303,62 +303,35 @@ void Core::loadProfile(bool force)
KConfigGroup activitiesConfig(m_profilesConfig, "Activities");
qCDebug(POWERDEVIL) << "Activities with settings:" << activitiesConfig.groupList() << activitiesConfig.keyList();
- // Are we mirroring an activity?
- if (activitiesConfig.group(activity).readEntry("mode", "None") == QStringLiteral("ActLike") &&
- activitiesConfig.group(activity).readEntry("actLike", QString()) != QStringLiteral("AC") &&
- activitiesConfig.group(activity).readEntry("actLike", QString()) != QStringLiteral("Battery") &&
- activitiesConfig.group(activity).readEntry("actLike", QString()) != QStringLiteral("LowBattery")) {
- // Yes, let's use that then
- activity = activitiesConfig.group(activity).readEntry("actLike", QString());
- qCDebug(POWERDEVIL) << "Activity is a mirror";
- }
-
KConfigGroup activityConfig = activitiesConfig.group(activity);
qCDebug(POWERDEVIL) << "Settings for loaded activity:" << activity << activityConfig.groupList() << activityConfig.keyList();
- // See if this activity has priority
- if (activityConfig.readEntry("mode", "None") == QStringLiteral("SeparateSettings")) {
- // Prioritize this profile over anything
- config = activityConfig.group("SeparateSettings");
- qCDebug(POWERDEVIL) << "Activity is enforcing a different profile";
- profileId = activity;
+ // let's load the current state's profile
+ if (m_batteriesPercent.isEmpty()) {
+ qCDebug(POWERDEVIL) << "No batteries found, loading AC";
+ profileId = QStringLiteral("AC");
} else {
- // It doesn't, let's load the current state's profile
- if (m_batteriesPercent.isEmpty()) {
- qCDebug(POWERDEVIL) << "No batteries found, loading AC";
+ // Compute the previous and current global percentage
+ const int percent = currentChargePercent();
+
+ if (backend()->acAdapterState() == BackendInterface::Plugged) {
profileId = QStringLiteral("AC");
- } else if (activityConfig.readEntry("mode", "None") == QStringLiteral("ActLike")) {
- if (activityConfig.readEntry("actLike", QString()) == QStringLiteral("AC") ||
- activityConfig.readEntry("actLike", QString()) == QStringLiteral("Battery") ||
- activityConfig.readEntry("actLike", QString()) == QStringLiteral("LowBattery")) {
- // Same as above, but with an existing profile
- config = m_profilesConfig.data()->group(activityConfig.readEntry("actLike", QString()));
- profileId = activityConfig.readEntry("actLike", QString());
- qCDebug(POWERDEVIL) << "Activity is mirroring a different profile";
- }
+ qCDebug(POWERDEVIL) << "Loading profile for plugged AC";
+ } else if (percent <= PowerDevilSettings::batteryLowLevel()) {
+ profileId = QStringLiteral("LowBattery");
+ qCDebug(POWERDEVIL) << "Loading profile for low battery";
} else {
- // Compute the previous and current global percentage
- const int percent = currentChargePercent();
-
- if (backend()->acAdapterState() == BackendInterface::Plugged) {
- profileId = QStringLiteral("AC");
- qCDebug(POWERDEVIL) << "Loading profile for plugged AC";
- } else if (percent <= PowerDevilSettings::batteryLowLevel()) {
- profileId = QStringLiteral("LowBattery");
- qCDebug(POWERDEVIL) << "Loading profile for low battery";
- } else {
- profileId = QStringLiteral("Battery");
- qCDebug(POWERDEVIL) << "Loading profile for unplugged AC";
- }
+ profileId = QStringLiteral("Battery");
+ qCDebug(POWERDEVIL) << "Loading profile for unplugged AC";
}
-
- config = m_profilesConfig.data()->group(profileId);
- qCDebug(POWERDEVIL) << "Activity is not forcing a profile";
}
+ config = m_profilesConfig.data()->group(profileId);
+ qCDebug(POWERDEVIL) << "Activity is not forcing a profile";
+
// Release any special inhibitions
{
- QHash<QString,int>::iterator i = m_sessionActivityInhibit.begin();
+ QHash<QString, int>::iterator i = m_sessionActivityInhibit.begin();
while (i != m_sessionActivityInhibit.end()) {
PolicyAgent::instance()->ReleaseInhibition(i.value());
i = m_sessionActivityInhibit.erase(i);
diff --git a/doc/kcm/index.docbook b/doc/kcm/index.docbook
index c57007105..56b2eadc5 100644
--- a/doc/kcm/index.docbook
+++ b/doc/kcm/index.docbook
@@ -153,14 +153,6 @@ If this option is chosen, a special behavior for activity can be chosen. If this
</para>
</listitem>
</varlistentry>
-<varlistentry>
-<term>Use separate settings (advanced users only)</term>
-<listitem>
-<para>
-This option allows users to choose the detail power saving settings for a separate activity. The settings are similar to the settings from the <link linkend="energy-saving-setting">Energy Saving page</link>.
-</para>
-</listitem>
-</varlistentry>
</variablelist>
</sect2>
diff --git a/kcmodule/activities/activityWidget.ui b/kcmodule/activities/activityWidget.ui
index 93859a184..c0cb1d29b 100644
--- a/kcmodule/activities/activityWidget.ui
+++ b/kcmodule/activities/activityWidget.ui
@@ -23,37 +23,6 @@
</property>
</widget>
</item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_2">
- <item>
- <widget class="QRadioButton" name="actLikeRadio">
- <property name="text">
- <string>Act like</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QComboBox" name="actLikeComboBox">
- <property name="enabled">
- <bool>false</bool>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- </layout>
- </item>
<item>
<widget class="QRadioButton" name="specialBehaviorRadio">
<property name="text">
@@ -132,20 +101,6 @@
</item>
</layout>
</item>
- <item>
- <widget class="QRadioButton" name="separateSettingsRadio">
- <property name="text">
- <string>Use separate settings</string>
- </property>
- </widget>
- </item>
- <item>
- <layout class="QVBoxLayout" name="separateSettingsLayout">
- <property name="leftMargin">
- <number>30</number>
- </property>
- </layout>
- </item>
</layout>
</item>
<item>
@@ -164,22 +119,5 @@
</layout>
</widget>
<resources/>
- <connections>
- <connection>
- <sender>actLikeRadio</sender>
- <signal>toggled(bool)</signal>
- <receiver>actLikeComboBox</receiver>
- <slot>setEnabled(bool)</slot>
- <hints>
- <hint type="sourcelabel">
- <x>44</x>
- <y>66</y>
- </hint>
- <hint type="destinationlabel">
- <x>133</x>
- <y>66</y>
- </hint>
- </hints>
- </connection>
- </connections>
+ <connections/>
</ui>
diff --git a/kcmodule/activities/activitywidget.cpp b/kcmodule/activities/activitywidget.cpp
index ed4bfef39..b1db8b68b 100644
--- a/kcmodule/activities/activitywidget.cpp
+++ b/kcmodule/activities/activitywidget.cpp
@@ -26,25 +26,21 @@
#include "powerdevilpowermanagement.h"
-#include <KConfigGroup>
#include <KActivities/Consumer>
+#include <KConfigGroup>
+#include <QLayout>
#include <Solid/Battery>
#include <Solid/Device>
-#include <actioneditwidget.h>
-#include <QLayout>
-ActivityWidget::ActivityWidget(const QString& activity, QWidget* parent)
+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) {
@@ -64,20 +60,10 @@ ActivityWidget::ActivityWidget(const QString& activity, QWidget* parent)
}
}
- m_actionEditWidget->setVisible(false);
- m_actionEditWidget->load();
-
- connect(m_ui->separateSettingsRadio, &QAbstractButton::toggled, m_actionEditWidget, &QWidget::setVisible);
-
- connect(m_ui->actLikeRadio, &QAbstractButton::toggled, this, &ActivityWidget::setChanged);
connect(m_ui->noSettingsRadio, &QAbstractButton::toggled, this, &ActivityWidget::setChanged);
- connect(m_ui->separateSettingsRadio, &QAbstractButton::toggled, this, &ActivityWidget::setChanged);
connect(m_ui->specialBehaviorRadio, &QAbstractButton::toggled, this, &ActivityWidget::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, &ActionEditWidget::changed, this, &ActivityWidget::changed);
}
ActivityWidget::~ActivityWidget()
@@ -103,50 +89,8 @@ void ActivityWidget::load()
}
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;
- const auto batteries = Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString());
- for (const Solid::Device &device : batteries) {
- const Solid::Battery *b = qobject_cast<const Solid::Battery*> (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);
-
- const QStringList activities = m_activityConsumer->activities();
- for (const QString &activity : 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") {
+ if (config.readEntry("mode", QString()) == "SpecialBehavior") {
m_ui->specialBehaviorRadio->setChecked(true);
KConfigGroup behaviorGroup = config.group("SpecialBehavior");
@@ -157,10 +101,6 @@ void ActivityWidget::load()
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();
}
}
@@ -169,10 +109,7 @@ 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()) {
+ if (m_ui->specialBehaviorRadio->isChecked()) {
config.writeEntry("mode", "SpecialBehavior");
KConfigGroup behaviorGroup = config.group("SpecialBehavior");
@@ -187,9 +124,6 @@ void ActivityWidget::save()
actionConfig.sync();
behaviorGroup.sync();
- } else if (m_ui->separateSettingsRadio->isChecked()) {
- config.writeEntry("mode", "SeparateSettings");
- m_actionEditWidget->save();
} else {
config.writeEntry("mode", "None");
}
diff --git a/kcmodule/activities/activitywidget.h b/kcmodule/activities/activitywidget.h
index de96c4873..0c4fa366a 100644
--- a/kcmodule/activities/activitywidget.h
+++ b/kcmodule/activities/activitywidget.h
@@ -24,7 +24,6 @@
#include <QWidget>
#include <KSharedConfig>
-class ActionEditWidget;
namespace KActivities
{
class Consumer;
@@ -55,7 +54,6 @@ private:
KSharedConfig::Ptr m_profilesConfig;
QString m_activity;
KActivities::Consumer *const m_activityConsumer;
- ActionEditWidget *const m_actionEditWidget;
};
#endif // ACTIVITYWIDGET_H
More information about the kde-doc-english
mailing list