Commit 169cfc63 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

QuickSettings: Make it possible for them not to be available

Makes it possible to QuickSettings components to only get listed if it
makes sense on the specific system.
parent 5a655901
......@@ -20,6 +20,15 @@ void QuickSetting::setEnabled(bool enabled)
Q_EMIT enabledChanged(enabled);
}
void QuickSetting::setAvailable(bool available)
{
if (m_available == available)
return;
m_available = available;
Q_EMIT availableChanged(available);
}
void QuickSetting::setSettingsCommand(const QString &settingsCommand)
{
if (m_settingsCommand == settingsCommand)
......
......@@ -18,6 +18,7 @@ class QuickSetting : public QObject
Q_PROPERTY(QString icon READ iconName WRITE setIconName REQUIRED NOTIFY iconNameChanged)
Q_PROPERTY(QString settingsCommand READ settingsCommand WRITE setSettingsCommand NOTIFY settingsCommandChanged)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
Q_PROPERTY(bool available READ isAvailable WRITE setAvailable NOTIFY availableChanged)
Q_PROPERTY(QQmlListProperty<QObject> children READ children CONSTANT)
Q_CLASSINFO("DefaultProperty", "children")
QML_NAMED_ELEMENT("QuickSetting")
......@@ -44,16 +45,22 @@ public:
{
return m_enabled;
}
bool isAvailable() const
{
return m_available;
}
void setText(const QString &text);
void setStatus(const QString &status);
void setIconName(const QString &iconName);
void setSettingsCommand(const QString &settingsCommand);
void setEnabled(bool enabled);
void setAvailable(bool available);
QQmlListProperty<QObject> children();
Q_SIGNALS:
void enabledChanged(bool enabled);
void availableChanged(bool available);
void textChanged(const QString &text);
void statusChanged(const QString &text);
void iconNameChanged(const QString &icon);
......@@ -61,6 +68,7 @@ Q_SIGNALS:
private:
bool m_enabled = true;
bool m_available = true;
QString m_text;
QString m_status;
QString m_iconName;
......
......@@ -91,7 +91,10 @@ void QuickSettingsModel::loadQuickSettings()
}
delete created;
} else {
m_quickSettings.push_back(createdSetting);
if (createdSetting->isAvailable()) {
m_quickSettings.push_back(createdSetting);
}
connect(createdSetting, &QuickSetting::availableChanged, this, &QuickSettingsModel::availabilityChanged);
}
}
......@@ -99,3 +102,24 @@ void QuickSettingsModel::loadQuickSettings()
endResetModel();
}
void QuickSettingsModel::availabilityChanged()
{
auto setting = qobject_cast<QuickSetting *>(sender());
if (setting->isAvailable()) {
if (!m_quickSettings.contains(setting)) {
auto idx = m_quickSettings.count();
beginInsertRows({}, idx, idx);
m_quickSettings.append(setting);
endInsertRows();
}
} else {
auto idx = m_quickSettings.indexOf(setting);
if (idx >= 0) {
beginRemoveRows({}, idx, idx);
m_quickSettings.removeAt(idx);
endRemoveRows();
}
}
}
......@@ -37,6 +37,7 @@ public:
private:
void loadQuickSettings();
void availabilityChanged();
bool m_loaded = false;
QList<QuickSetting *> m_quickSettings;
......
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