Commit d80f738f authored by Eike Hein's avatar Eike Hein Committed by Nate Graham
Browse files

[kicker] Don't add invalid actions to the system action model

The system actions model recently changed behavior to always present all
possible actions, with `AbstractEntry::isValid` driving the model role
`Kicker::DisabledRole` so that views can e.g. grey out unavailable

This was perceived as a regression by users who are annoyed at e.g.
`Hibernate` being visible when their system setup precludes it more or
less permanently.

This patch reverts this behavior.

Note that the dynamic approach we had permanently wasn't very great
anyway, as the associated favorites models would remove entries when
they became invalid, and they wouldn't come back automatically when the
entry were to become valid again. In effect that means when you added one
of these actions to e.g. the Kicker sidebar and it became unavailable
it would disappear until re-added anyways.

I can imagine use cases where dynamic behavior would be useful to have -
let's say disabling Shutdown/Reboot while a critical system update is
being performed. But in that case we'd need to fix the favorites
behavior and add some way to inform the user why the action is disabled
for a good user experienced anyhow.


(cherry picked from commit fcdbbda3)
parent 004fbbd8
......@@ -28,27 +28,7 @@
SystemModel::SystemModel(QObject *parent) : AbstractModel(parent)
m_favoritesModel = new SimpleFavoritesModel(this);
m_entries[SystemEntry::LockSession] = new SystemEntry(this, SystemEntry::LockSession);
m_entries[SystemEntry::LogoutSession] = new SystemEntry(this, SystemEntry::LogoutSession);
m_entries[SystemEntry::SaveSession] = new SystemEntry(this, SystemEntry::SaveSession);
m_entries[SystemEntry::SwitchUser] = new SystemEntry(this, SystemEntry::SwitchUser);
m_entries[SystemEntry::Suspend] = new SystemEntry(this, SystemEntry::Suspend);
m_entries[SystemEntry::Hibernate] = new SystemEntry(this, SystemEntry::Hibernate);
m_entries[SystemEntry::Reboot] = new SystemEntry(this, SystemEntry::Reboot);
m_entries[SystemEntry::Shutdown] = new SystemEntry(this, SystemEntry::Shutdown);
for (SystemEntry *entry : m_entries.values()) {
QObject::connect(entry, &SystemEntry::isValidChanged, this,
[this, entry]() {
const QModelIndex &idx = index(entry->action(), 0);
emit dataChanged(idx, idx, QVector<int>{Kicker::DisabledRole});
QObject::connect(entry, &SystemEntry::isValidChanged, m_favoritesModel, &AbstractModel::refresh);
......@@ -67,7 +47,7 @@ QVariant SystemModel::data(const QModelIndex &index, int role) const
return QVariant();
const SystemEntry *entry = m_entries.value(static_cast<SystemEntry::Action>(index.row() + 1));
const SystemEntry *entry = m_entries.value(index.row());
if (role == Qt::DisplayRole) {
return entry->name();
......@@ -98,7 +78,7 @@ int SystemModel::rowCount(const QModelIndex &parent) const
bool SystemModel::trigger(int row, const QString &actionId, const QVariant &argument)
if (row >= 0 && row < m_entries.count()) {
m_entries.value(static_cast<SystemEntry::Action>(row + 1))->run(actionId, argument);>run(actionId, argument);
return true;
......@@ -108,5 +88,34 @@ bool SystemModel::trigger(int row, const QString &actionId, const QVariant &argu
void SystemModel::refresh()
void SystemModel::populate()
auto addIfValid = [=](const SystemEntry::Action action) {
SystemEntry *entry = new SystemEntry(this, action);
if (entry->isValid()) {
m_entries << entry;
QObject::connect(entry, &SystemEntry::isValidChanged, this,
&AbstractModel::refresh, Qt::UniqueConnection);
......@@ -43,7 +43,9 @@ class SystemModel : public AbstractModel
void refresh() override;
QHash<SystemEntry::Action, SystemEntry *> m_entries;
void populate();
QVector<SystemEntry *> m_entries;
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