Commit 2f84b07b authored by Devin Lin's avatar Devin Lin 🎨
Browse files

quicksettings: Add save and update timers so kcm ordering is always correct

parent bba95726
Pipeline #153265 passed with stages
in 1 minute and 12 seconds
......@@ -16,6 +16,7 @@ SavedQuickSettings::SavedQuickSettings(QObject *parent)
, m_enabledQSModel{new SavedQuickSettingsModel{this}}
, m_disabledQSModel{new SavedQuickSettingsModel{this}}
, m_updateTimer{new QTimer{this}}
, m_saveTimer{new QTimer{this}}
{
// throttle model updates from config, to avoid performance issues with fast reloading
m_updateTimer->setInterval(2000);
......@@ -24,6 +25,13 @@ SavedQuickSettings::SavedQuickSettings(QObject *parent)
refreshModel();
});
// throttle saving so that we don't have conflicts while writing and then getting notified about updates
m_saveTimer->setInterval(1000);
m_saveTimer->setSingleShot(true);
connect(m_saveTimer, &QTimer::timeout, this, [this]() {
saveModel();
});
// load quicksettings packages
auto packages = KPackage::PackageLoader::self()->listPackages(QStringLiteral("KPackage/GenericQML"), "plasma/quicksettings");
......@@ -51,7 +59,10 @@ SavedQuickSettings::SavedQuickSettings(QObject *parent)
m_enabledPackages.push_back(metaData);
}
saveModel();
m_saveTimer->start();
if (m_updateTimer->isActive()) {
m_updateTimer->start(); // reset update timer if it's running
}
});
connect(m_disabledQSModel, &SavedQuickSettingsModel::dataUpdated, this, [this](QList<KPluginMetaData *> data) -> void {
m_disabledPackages.clear();
......@@ -59,13 +70,24 @@ SavedQuickSettings::SavedQuickSettings(QObject *parent)
m_disabledPackages.push_back(metaData);
}
saveModel();
m_saveTimer->start();
if (m_updateTimer->isActive()) {
m_updateTimer->start(); // reset update timer if it's running
}
});
// load
refreshModel();
}
SavedQuickSettings::~SavedQuickSettings()
{
// save immediately if was requested
if (m_saveTimer->isActive()) {
saveModel();
}
}
SavedQuickSettingsModel *SavedQuickSettings::enabledQuickSettingsModel() const
{
return m_enabledQSModel;
......
......@@ -29,6 +29,7 @@ class SavedQuickSettings : public QObject
public:
SavedQuickSettings(QObject *parent = nullptr);
~SavedQuickSettings();
SavedQuickSettingsModel *enabledQuickSettingsModel() const;
SavedQuickSettingsModel *disabledQuickSettingsModel() const;
......@@ -46,4 +47,5 @@ private:
SavedQuickSettingsModel *m_disabledQSModel;
QTimer *m_updateTimer;
QTimer *m_saveTimer;
};
......@@ -41,11 +41,7 @@ void SavedQuickSettingsModel::moveRow(int oldIndex, int newIndex)
return;
}
if (oldIndex < newIndex) {
++newIndex;
}
Q_EMIT beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
Q_EMIT beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex + (oldIndex < newIndex ? 1 : 0));
std::iter_swap(m_data.begin() + oldIndex, m_data.begin() + newIndex);
Q_EMIT endMoveRows();
......
......@@ -92,11 +92,11 @@ KCM.SimpleKCM {
}
Kirigami.Icon {
visible: model.icon !== ""
source: model.icon
Layout.rightMargin: (model.icon !== "") ? Kirigami.Units.largeSpacing : 0
implicitWidth: (model.icon !== "") ? Kirigami.Units.iconSizes.small : 0
implicitHeight: (model.icon !== "") ? Kirigami.Units.iconSizes.small : 0
visible: model && model.icon !== ""
source: model ? model.icon : ""
Layout.rightMargin: (model && model.icon !== "") ? Kirigami.Units.largeSpacing : 0
implicitWidth: (model && model.icon !== "") ? Kirigami.Units.iconSizes.small : 0
implicitHeight: (model && model.icon !== "") ? Kirigami.Units.iconSizes.small : 0
}
ColumnLayout {
......@@ -105,7 +105,7 @@ KCM.SimpleKCM {
QQC2.Label {
Layout.fillWidth: true
text: model.name
text: model ? model.name : ""
elide: Text.ElideRight
}
}
......
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