diff --git a/imports/activitymanager/sortedactivitiesmodel.cpp b/imports/activitymanager/sortedactivitiesmodel.cpp --- a/imports/activitymanager/sortedactivitiesmodel.cpp +++ b/imports/activitymanager/sortedactivitiesmodel.cpp @@ -23,9 +23,10 @@ // Qt #include #include +#include // KDE -#include +#include #include #include #include @@ -36,43 +37,58 @@ #include #include +#define PLASMACONFIG "plasma-org.kde.plasma.desktop-appletsrc" + namespace { class BackgroundCache { public: BackgroundCache() : initialized(false) - , plasmaConfig("plasma-org.kde.plasma.desktop-appletsrc") + , plasmaConfig(KSharedConfig::openConfig(PLASMACONFIG)) + , updateTimer() { using namespace std::placeholders; const auto configFile = QStandardPaths::writableLocation( QStandardPaths::GenericConfigLocation) + - QLatin1Char('/') + plasmaConfig.name(); + QLatin1Char('/') + PLASMACONFIG; KDirWatch::self()->addFile(configFile); QObject::connect(KDirWatch::self(), &KDirWatch::dirty, [this] (const QString &file) { settingsFileChanged(file); }); QObject::connect(KDirWatch::self(), &KDirWatch::created, [this] (const QString &file) { settingsFileChanged(file); }); + + updateTimer.setSingleShot(true); + updateTimer.setInterval(500); + + QObject::connect(&updateTimer, &QTimer::timeout, + [this] () { + plasmaConfig->reparseConfiguration(); + reload(); + }); } void settingsFileChanged(const QString &file) { - if (!file.endsWith(plasmaConfig.name())) return; - - plasmaConfig.reparseConfiguration(); + if (!file.endsWith(PLASMACONFIG)) { + qDebug() << "Updated GREPME a wrong file: " << file; + return; + } if (initialized) { - reload(false); + // Requesting reload a bit later - we want plasma to finish + // writing the file first + updateTimer.start(); } } void subscribe(SortedActivitiesModel *model) { if (!initialized) { - reload(true); + reload(); } models << model; @@ -108,8 +124,10 @@ return QString(); } - void reload(bool) + void reload() { + updateTimer.stop(); + auto newForActivity = forActivity; // contains activities for which the wallpaper @@ -169,14 +187,15 @@ } KConfigGroup plasmaConfigContainments() { - return plasmaConfig.group("Containments"); + return plasmaConfig->group("Containments"); } QHash forActivity; QList models; bool initialized; - KConfig plasmaConfig; + KSharedConfig::Ptr plasmaConfig; + QTimer updateTimer; }; @@ -187,6 +206,7 @@ static BackgroundCache cache; return cache; } + } SortedActivitiesModel::SortedActivitiesModel(QVector states, QObject *parent)