Commit b311aa9a authored by David Redondo's avatar David Redondo 🏎
Browse files

energy: Remove wakeups related code

Wakeup API has been removed in UPower and was unfunctional
for years.
See https://gitlab.freedesktop.org/upower/upower/-/commit/9058d45685d1c7c08d52fb64c393fed9eeed542b
parent 612ab240
Pipeline #196074 passed with stage
in 2 minutes and 2 seconds
......@@ -8,8 +8,6 @@ set(kcm_energyinfo_SRCS
kcm.h
statisticsprovider.cpp
statisticsprovider.h
wakeupmodel.cpp
wakeupmodel.h
)
kcoreaddons_add_plugin(kcm_energyinfo SOURCES ${kcm_energyinfo_SRCS} INSTALL_NAMESPACE "plasma/kcms")
......
......@@ -33,7 +33,6 @@ KCMEnergyInfo::KCMEnergyInfo(QObject *parent, const KPluginMetaData &data, const
: ConfigModule(parent, data, args)
{
qmlRegisterAnonymousType<BatteryModel>("org.kde.kinfocenter.energy.private", 1);
qmlRegisterAnonymousType<WakeUpModel>("org.kde.kinfocenter.energy.private", 1);
qmlRegisterType<StatisticsProvider>("org.kde.kinfocenter.energy.private", 1, 0, "HistoryModel");
qmlRegisterUncreatableType<BatteryModel>("org.kde.kinfocenter.energy.private", 1, 0, "BatteryModel", QStringLiteral("Use BatteryModel"));
......@@ -44,8 +43,6 @@ KCMEnergyInfo::KCMEnergyInfo(QObject *parent, const KPluginMetaData &data, const
setAboutData(about);
m_batteries = new BatteryModel(this);
m_wakeUps = new WakeUpModel(this);
}
#include "kcm.moc"
......@@ -7,7 +7,6 @@
#ifndef KCM_ENERGYINFO_H
#define KCM_ENERGYINFO_H
#include "wakeupmodel.h"
#include <KQuickAddons/ConfigModule>
class BatteryModel;
......@@ -17,8 +16,6 @@ class KCMEnergyInfo : public KQuickAddons::ConfigModule
Q_PROPERTY(BatteryModel *batteries READ batteries CONSTANT)
Q_PROPERTY(WakeUpModel *wakeUps READ wakeUps CONSTANT)
public:
explicit KCMEnergyInfo(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
~KCMEnergyInfo() override = default;
......@@ -28,17 +25,9 @@ public:
return m_batteries;
}
WakeUpModel *wakeUps() const
{
return m_wakeUps;
}
private:
BatteryModel *m_batteries = nullptr;
WakeUpModel *m_wakeUps = nullptr;
int m_wakeUpsCount = 0;
};
Q_DECLARE_METATYPE(QList<QPointF>)
......
......@@ -42,7 +42,6 @@ KCM.SimpleKCM {
}
}
property bool showWakeUps: true
property int historyType: HistoryModel.ChargeType
readonly property var details: [
......@@ -106,7 +105,7 @@ KCM.SimpleKCM {
Kirigami.PlaceholderMessage {
anchors.centerIn: parent
visible: kcm.batteries.count <= 0 && kcm.wakeUps.count <= 0 && history.count <= 0
visible: kcm.batteries.count <= 0 && history.count <= 0
width: parent.width - (Kirigami.Units.largeSpacing * 4)
text: i18nc("@info:status", "No energy information available on this system")
icon.name: "utilities-energy-monitor"
......@@ -142,8 +141,6 @@ KCM.SimpleKCM {
checked = Qt.binding(function() {
return model.battery == root.currentBattery
})
showWakeUps = (index === 0)
}
ColumnLayout {
......@@ -322,107 +319,6 @@ KCM.SimpleKCM {
}
}
ColumnLayout {
Layout.fillWidth: true
spacing: units.smallSpacing
visible: showWakeUps && kcm.wakeUps.count > 0
RowLayout {
Layout.fillWidth: true
Kirigami.Heading {
Layout.fillWidth: true
Layout.columnSpan: 2
level: 4
text: i18n("Application Energy Consumption")
}
}
GridLayout {
id: wakeUpsGrid
Layout.fillWidth: true
rows: compact ? kcm.wakeUps.count : kcm.wakeUps.count / 2
flow: GridLayout.TopToBottom
rowSpacing: units.smallSpacing
columnSpacing: units.smallSpacing
property int barWidth: (compact ? root.width - units.gridUnit: root.width / 2) - units.smallSpacing * 2
Repeater {
model: showWakeUps ? kcm.wakeUps : null
PlasmaCore.ToolTipArea { // FIXME use widget style tooltip
Layout.minimumWidth: wakeUpsGrid.barWidth
Layout.maximumWidth: wakeUpsGrid.barWidth
height: childrenRect.height
z: 2 // since the progress bar eats mouse events
mainText: model.prettyName || model.name
subText: {
var text = ""
if (model.prettyName && model.name !== model.prettyName) {
text += i18n("Path: %1", model.name) + "\n"
}
if (model.pid) {
text += i18n("PID: %1", model.pid) + "\n"
}
// FIXME format decimals
text += i18n("Wakeups per second: %1 (%2%)", Math.round(model.wakeUps * 100) / 100, Math.round(model.wakeUps / kcm.wakeUps.total * 100)) + "\n"
if (model.details) {
text += i18n("Details: %1", model.details)
}
return text
}
icon: model.iconName
RowLayout {
id: wakeUpItemRow
width: parent.width
QIconItem {
width: units.iconSizes.medium
height: width
icon: model.iconName
}
ColumnLayout {
Layout.fillWidth: true
spacing: 0
RowLayout {
Layout.fillWidth: true
QQC2.Label {
Layout.fillWidth: true
elide: Text.ElideRight
text: model.prettyName || model.name
}
/*QQC2.Label {
text: i18n("System Service")
visible: !model.userSpace
opacity: 0.6
}*/
}
QQC2.ProgressBar {
Layout.fillWidth: true
from: 0
to: 100
value: model.wakeUps / kcm.wakeUps.total * 100
}
}
}
}
}
}
}
Rectangle {
Layout.fillWidth: true
height: 1
color: Kirigami.Theme.textColor // FIXME palette
//Layout.topMargin: (compact ? units.gridUnit * 2 : 0)
visible: wakeUpsGrid.visible
}
ColumnLayout {
id: detailsColumn
spacing: 0
......
/*
* SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "wakeupmodel.h"
#include <QDBusConnection>
#include <QDBusMetaType>
#include <QDBusPendingReply>
#include <QDebug>
#include <KService>
class WakeUpReply
{
public:
bool fromUserSpace = false;
quint32 id = 0;
double wakeUpsPerSecond = 0.0;
QString cmdline;
QString details;
};
Q_DECLARE_METATYPE(WakeUpReply)
const QDBusArgument &operator<<(QDBusArgument &argument, const WakeUpReply &data)
{
argument.beginStructure();
argument << data.fromUserSpace << data.id << data.wakeUpsPerSecond << data.cmdline << data.details;
argument.endStructure();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, WakeUpReply &data)
{
argument.beginStructure();
argument >> data.fromUserSpace >> data.id >> data.wakeUpsPerSecond >> data.cmdline >> data.details;
argument.endStructure();
return argument;
}
static const int s_maximumEntries = 10;
WakeUpModel::WakeUpModel(QObject *parent)
: QAbstractListModel(parent)
{
qDBusRegisterMetaType<WakeUpReply>();
qDBusRegisterMetaType<QList<WakeUpReply>>();
if (!QDBusConnection::systemBus().connect(QStringLiteral("org.freedesktop.UPower"),
QStringLiteral("/org/freedesktop/UPower/Wakeups"),
QStringLiteral("org.freedesktop.UPower.Wakeups"),
QStringLiteral("DataChanged"),
this,
SLOT(reload()))) {
qDebug() << "Error connecting to wakeup data changes via dbus";
}
reload();
}
void WakeUpModel::reload()
{
// It is possible that DataChanged is emitted very quickly, up to the point
// that upower won't be able to respond, resulting in errors due to maximum number
// of pending replies.
// One update per second should be enough.
if (!m_lastReload.isNull() && m_lastReload.secsTo(QTime::currentTime()) < 1) {
return;
}
m_lastReload = QTime::currentTime();
QDBusPendingReply<QList<WakeUpReply>> reply =
QDBusConnection::systemBus().asyncCall(QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.UPower"),
QStringLiteral("/org/freedesktop/UPower/Wakeups"),
QStringLiteral("org.freedesktop.UPower.Wakeups"),
QStringLiteral("GetData")));
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<QList<WakeUpReply>> reply = *watcher;
watcher->deleteLater();
if (reply.isError()) {
qWarning() << "Failed to get wakeup statistics from UPower";
return;
}
const bool resetModel = m_data.isEmpty();
if (resetModel) {
beginResetModel();
}
m_total = 0.0;
m_combinedData.clear();
m_data.clear();
auto values = reply.value();
for (auto it = values.constBegin(); it != values.constEnd(); ++it) {
if (!(*it).fromUserSpace) {
continue;
}
const QString appName = (*it).cmdline.split(QLatin1Char(' '), Qt::SkipEmptyParts).first(); // ugly
if (!m_combinedData.contains(appName)) {
m_combinedData[appName].name = appName;
m_combinedData[appName].userSpace = (*it).fromUserSpace;
}
m_combinedData[appName].wakeUps += (*it).wakeUpsPerSecond;
if ((*it).id) {
m_combinedData[appName].pid = (*it).id;
}
if (!(*it).details.isEmpty()) {
m_combinedData[appName].details = (*it).details;
}
m_total += (*it).wakeUpsPerSecond;
}
for (auto it = m_combinedData.begin(); it != m_combinedData.end(); ++it) {
const QString &name = (*it).name;
auto existingService = m_applicationInfo.find(name);
if (existingService != m_applicationInfo.end()) {
(*it).prettyName = (*existingService).first;
(*it).iconName = (*existingService).second;
} else {
KService::Ptr service = KService::serviceByStorageId(name + ".desktop");
if (service) {
it->prettyName = service->property(QStringLiteral("Name"), QVariant::Invalid).toString();
it->iconName = service->icon();
m_applicationInfo.insert(name, qMakePair((*it).prettyName, (*it).iconName));
} else {
// use the app name as fallback icon
(*it).iconName = name.split(QLatin1Char('/'), Qt::SkipEmptyParts).last().toLower();
}
}
m_data.append((*it));
}
m_combinedData.clear();
std::sort(m_data.begin(), m_data.end(), [](const WakeUpData &a, const WakeUpData &b) {
return a.wakeUps > b.wakeUps;
});
emit totalChanged();
emit countChanged();
if (resetModel) {
endResetModel();
} else {
emit dataChanged(index(0, 0), index(s_maximumEntries - 1, 0));
}
});
}
QVariant WakeUpModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= m_data.count() || index.row() >= s_maximumEntries) {
return QVariant();
}
switch (role) {
case PidRole:
return m_data.at(index.row()).pid;
case NameRole:
return m_data.at(index.row()).name;
case PrettyNameRole:
return m_data.at(index.row()).prettyName;
case IconNameRole:
return m_data.at(index.row()).iconName;
case WakeUpsRole:
return m_data.at(index.row()).wakeUps;
case PercentRole:
return m_data.at(index.row()).percent;
case UserSpaceRole:
return m_data.at(index.row()).userSpace;
case DetailsRole:
return m_data.at(index.row()).details;
}
return QVariant();
}
int WakeUpModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return qMin(m_data.count(), s_maximumEntries);
}
QHash<int, QByteArray> WakeUpModel::roleNames() const
{
return {{PidRole, "pid"},
{NameRole, "name"},
{PrettyNameRole, "prettyName"},
{IconNameRole, "iconName"},
{WakeUpsRole, "wakeUps"},
{PercentRole, "percent"},
{UserSpaceRole, "userSpace"},
{DetailsRole, "details"}};
}
/*
* SPDX-FileCopyrightText: 2015 Kai Uwe Broulik <kde@privat.broulik.de>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef KCM_ENERGYINFO_WAKEUPMODEL_H
#define KCM_ENERGYINFO_WAKEUPMODEL_H
#include <QAbstractListModel>
#include <QHash>
#include <QList>
#include <QPair>
#include <QTime>
class WakeUpData
{
public:
uint pid = 0;
QString name;
QString prettyName;
QString iconName;
qreal wakeUps = 0.0;
qreal percent = 0.0;
bool userSpace = false;
QString details;
};
class WakeUpModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(qreal total READ total NOTIFY totalChanged)
public:
explicit WakeUpModel(QObject *parent);
~WakeUpModel() override = default;
enum Roles {
PidRole = Qt::UserRole,
NameRole,
PrettyNameRole = Qt::DisplayRole,
IconNameRole = Qt::DecorationRole,
WakeUpsRole = Qt::UserRole + 2,
PercentRole,
UserSpaceRole,
DetailsRole,
};
qreal total() const
{
return m_total;
}
QVariant data(const QModelIndex &index, int role) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QHash<int, QByteArray> roleNames() const override;
public slots:
void reload();
signals:
void countChanged();
void totalChanged();
private:
QList<WakeUpData> m_data;
QHash<QString, WakeUpData> m_combinedData;
qreal m_total = 0.0;
QHash<QString, QPair<QString, QString>> m_applicationInfo;
QTime m_lastReload;
};
#endif // KCM_ENERGYINFO_WAKEUPMODEL_H
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