Commit 76a3570a authored by David Edmundson's avatar David Edmundson
Browse files

Add method CGroupDataModel::isAvailable

This returns true if the root is pointing to a valid path. The idea
being that non-systemd systems won't have applications scoped correctly,
nor a relevant user slice.

By communicating this we can dislpay the entry as not working in the UI.


(cherry picked from commit 6d429604)
parent 7c46d893
......@@ -48,6 +48,7 @@ public:
QHash<QString, KSysGuard::ProcessAttribute* > m_availableAttributes;
QVector<KSysGuard::ProcessAttribute* > m_enabledAttributes;
bool m_available = false;
QString m_root;
QScopedPointer<CGroup> m_rootGroup;
......@@ -367,9 +368,22 @@ void CGroupDataModel::setRoot(const QString &root)
return;
}
d->m_root = root;
d->m_rootGroup.reset(new CGroup(root));
emit rootChanged();
QMetaObject::invokeMethod(this, [this] {update();}, Qt::QueuedConnection);
const QString path = CGroup::cgroupSysBasePath() + root;
bool available = QFile::exists(path);
if (available) {
d->m_rootGroup.reset(new CGroup(root));
} else {
d->m_rootGroup.reset();
}
if (available != d->m_available) {
d->m_available = available;
emit availableChanged();
}
}
void CGroupDataModel::update()
......@@ -443,6 +457,11 @@ void CGroupDataModel::update(CGroup *node)
}
}
bool CGroupDataModel::isAvailable() const
{
return d->m_available;
}
QVector<Process*> CGroupDataModelPrivate::processesFor(CGroup *app)
{
if (m_processMap.contains(app)) {
......
......@@ -59,6 +59,8 @@ class Q_DECL_EXPORT CGroupDataModel : public QAbstractItemModel
*/
Q_PROPERTY(QString setRoot READ root WRITE setRoot NOTIFY rootChanged)
Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged)
public:
CGroupDataModel(QObject *parent = nullptr);
CGroupDataModel(const QString &root, QObject *parent = nullptr);
......@@ -114,10 +116,13 @@ public:
*/
void update();
bool isAvailable() const;
Q_SIGNALS:
void enabledAttributesChanged();
void enabledChanged();
void rootChanged();
void availableChanged();
protected:
virtual bool filterAcceptsCGroup(const QString &id);
......
Markdown is supported
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