mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
quicksettings: Add save and update timers so kcm ordering is always correct
This commit is contained in:
parent
bba95726cf
commit
2f84b07bbc
4 changed files with 33 additions and 13 deletions
|
|
@ -16,6 +16,7 @@ SavedQuickSettings::SavedQuickSettings(QObject *parent)
|
||||||
, m_enabledQSModel{new SavedQuickSettingsModel{this}}
|
, m_enabledQSModel{new SavedQuickSettingsModel{this}}
|
||||||
, m_disabledQSModel{new SavedQuickSettingsModel{this}}
|
, m_disabledQSModel{new SavedQuickSettingsModel{this}}
|
||||||
, m_updateTimer{new QTimer{this}}
|
, m_updateTimer{new QTimer{this}}
|
||||||
|
, m_saveTimer{new QTimer{this}}
|
||||||
{
|
{
|
||||||
// throttle model updates from config, to avoid performance issues with fast reloading
|
// throttle model updates from config, to avoid performance issues with fast reloading
|
||||||
m_updateTimer->setInterval(2000);
|
m_updateTimer->setInterval(2000);
|
||||||
|
|
@ -24,6 +25,13 @@ SavedQuickSettings::SavedQuickSettings(QObject *parent)
|
||||||
refreshModel();
|
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
|
// load quicksettings packages
|
||||||
auto packages = KPackage::PackageLoader::self()->listPackages(QStringLiteral("KPackage/GenericQML"), "plasma/quicksettings");
|
auto packages = KPackage::PackageLoader::self()->listPackages(QStringLiteral("KPackage/GenericQML"), "plasma/quicksettings");
|
||||||
|
|
||||||
|
|
@ -51,7 +59,10 @@ SavedQuickSettings::SavedQuickSettings(QObject *parent)
|
||||||
m_enabledPackages.push_back(metaData);
|
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 {
|
connect(m_disabledQSModel, &SavedQuickSettingsModel::dataUpdated, this, [this](QList<KPluginMetaData *> data) -> void {
|
||||||
m_disabledPackages.clear();
|
m_disabledPackages.clear();
|
||||||
|
|
@ -59,13 +70,24 @@ SavedQuickSettings::SavedQuickSettings(QObject *parent)
|
||||||
m_disabledPackages.push_back(metaData);
|
m_disabledPackages.push_back(metaData);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveModel();
|
m_saveTimer->start();
|
||||||
|
if (m_updateTimer->isActive()) {
|
||||||
|
m_updateTimer->start(); // reset update timer if it's running
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// load
|
// load
|
||||||
refreshModel();
|
refreshModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SavedQuickSettings::~SavedQuickSettings()
|
||||||
|
{
|
||||||
|
// save immediately if was requested
|
||||||
|
if (m_saveTimer->isActive()) {
|
||||||
|
saveModel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SavedQuickSettingsModel *SavedQuickSettings::enabledQuickSettingsModel() const
|
SavedQuickSettingsModel *SavedQuickSettings::enabledQuickSettingsModel() const
|
||||||
{
|
{
|
||||||
return m_enabledQSModel;
|
return m_enabledQSModel;
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ class SavedQuickSettings : public QObject
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SavedQuickSettings(QObject *parent = nullptr);
|
SavedQuickSettings(QObject *parent = nullptr);
|
||||||
|
~SavedQuickSettings();
|
||||||
|
|
||||||
SavedQuickSettingsModel *enabledQuickSettingsModel() const;
|
SavedQuickSettingsModel *enabledQuickSettingsModel() const;
|
||||||
SavedQuickSettingsModel *disabledQuickSettingsModel() const;
|
SavedQuickSettingsModel *disabledQuickSettingsModel() const;
|
||||||
|
|
@ -46,4 +47,5 @@ private:
|
||||||
SavedQuickSettingsModel *m_disabledQSModel;
|
SavedQuickSettingsModel *m_disabledQSModel;
|
||||||
|
|
||||||
QTimer *m_updateTimer;
|
QTimer *m_updateTimer;
|
||||||
|
QTimer *m_saveTimer;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,7 @@ void SavedQuickSettingsModel::moveRow(int oldIndex, int newIndex)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldIndex < newIndex) {
|
Q_EMIT beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex + (oldIndex < newIndex ? 1 : 0));
|
||||||
++newIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
Q_EMIT beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
|
|
||||||
std::iter_swap(m_data.begin() + oldIndex, m_data.begin() + newIndex);
|
std::iter_swap(m_data.begin() + oldIndex, m_data.begin() + newIndex);
|
||||||
Q_EMIT endMoveRows();
|
Q_EMIT endMoveRows();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,11 +92,11 @@ KCM.SimpleKCM {
|
||||||
}
|
}
|
||||||
|
|
||||||
Kirigami.Icon {
|
Kirigami.Icon {
|
||||||
visible: model.icon !== ""
|
visible: model && model.icon !== ""
|
||||||
source: model.icon
|
source: model ? model.icon : ""
|
||||||
Layout.rightMargin: (model.icon !== "") ? Kirigami.Units.largeSpacing : 0
|
Layout.rightMargin: (model && model.icon !== "") ? Kirigami.Units.largeSpacing : 0
|
||||||
implicitWidth: (model.icon !== "") ? Kirigami.Units.iconSizes.small : 0
|
implicitWidth: (model && model.icon !== "") ? Kirigami.Units.iconSizes.small : 0
|
||||||
implicitHeight: (model.icon !== "") ? Kirigami.Units.iconSizes.small : 0
|
implicitHeight: (model && model.icon !== "") ? Kirigami.Units.iconSizes.small : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
|
|
@ -105,7 +105,7 @@ KCM.SimpleKCM {
|
||||||
|
|
||||||
QQC2.Label {
|
QQC2.Label {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
text: model.name
|
text: model ? model.name : ""
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue