Commit cb02df61 authored by Harald Sitter's avatar Harald Sitter 🏳🌈
Browse files

do not needlessly allocate stuff when the potd isn't even used

this changes initialization to be lazyly done. we'll now always read the
config first and only if the config actually uses potd we'll initialize
a consumer. this effectively reduces the by-default weight of this
module
to a kdirwatch only
parent ccef7d54
......@@ -7,18 +7,14 @@
K_PLUGIN_CLASS_WITH_JSON(PotdModule, "kded_potd.json")
PotdModule::PotdModule(QObject* parent, const QList<QVariant>&): KDEDModule(parent)
PotdModule::PotdModule(QObject* parent, const QList<QVariant>&)
: KDEDModule(parent)
, configPath(QStandardPaths::locate(QStandardPaths::ConfigLocation, QStringLiteral("kscreenlockerrc")))
{
consumer = new Plasma::DataEngineConsumer();
engine = consumer->dataEngine(QStringLiteral("potd"));
configPath = QStandardPaths::locate(QStandardPaths::ConfigLocation, QStringLiteral("kscreenlockerrc"));
previousSource = getSource();
engine->connectSource(previousSource, this); // trigger caching, no need to handle data
watcher = new QFileSystemWatcher(this);
watcher->addPath(configPath);
connect(watcher, &QFileSystemWatcher::fileChanged, this, &PotdModule::fileChanged);
fileChanged(configPath);
}
PotdModule::~PotdModule()
......@@ -29,9 +25,21 @@ PotdModule::~PotdModule()
void PotdModule::fileChanged(const QString &path)
{
Q_UNUSED(path);
engine->disconnectSource(previousSource, this);
if (engine) {
engine->disconnectSource(previousSource, this);
}
previousSource = getSource();
engine->connectSource(previousSource, this);
if (!previousSource.isEmpty()) {
if (!consumer) {
consumer = new Plasma::DataEngineConsumer;
engine = consumer->dataEngine(QStringLiteral("potd"));
engine->connectSource(previousSource, this); // trigger caching, no need to handle data
}
engine->connectSource(previousSource, this);
}
// For some reason, Qt *rc files are always recreated instead of modified.
// Recreated files were removed from watchers and have to be added again.
......
......@@ -28,8 +28,8 @@ private Q_SLOTS:
private:
QString getSource();
Plasma::DataEngineConsumer *consumer;
Plasma::DataEngine *engine;
Plasma::DataEngineConsumer *consumer = nullptr;
Plasma::DataEngine *engine = nullptr;
QFileSystemWatcher *watcher;
QString configPath;
QString previousSource;
......
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