Changeset View
Standalone View
kdeds/potd/kded_potd.cpp
- This file was added.
1 | #include "kded_potd.h" | ||||
---|---|---|---|---|---|
2 | | ||||
3 | #include <QDebug> | ||||
4 | #include <kpluginfactory.h> | ||||
davidre: QDebug | |||||
guoyunhe: Will remove. | |||||
5 | #include <kpluginloader.h> | ||||
6 | | ||||
7 | #define COMPONENT_NAME "potd" | ||||
8 | | ||||
9 | K_PLUGIN_FACTORY_WITH_JSON(PotdModuleFactory, | ||||
10 | "kded_potd.json", | ||||
davidre: still leaks | |||||
11 | registerPlugin<PotdModule>();) | ||||
davidre: unused | |||||
guoyunhe: Will remove. | |||||
12 | | ||||
13 | PotdModule::PotdModule(QObject* parent, const QList<QVariant>&): KDEDModule(parent) | ||||
davidre: You can use K_PLUGIN_CLASS_WITH_JSON | |||||
guoyunhe: Changed | |||||
14 | { | ||||
15 | consumer = new Plasma::DataEngineConsumer(); | ||||
16 | engine = consumer->dataEngine(QStringLiteral("potd")); | ||||
17 | KConfig config(QStandardPaths::locate(QStandardPaths::ConfigLocation, QStringLiteral("/kscreenlockerrc"))); | ||||
18 | source = getSource(); | ||||
19 | engine->connectSource(source, this); | ||||
davidre: this leaks | |||||
guoyunhe: Fixed. | |||||
20 | } | ||||
21 | | ||||
22 | PotdModule::~PotdModule() | ||||
23 | { | ||||
24 | } | ||||
25 | | ||||
26 | void PotdModule::dataUpdated(const QString& sourceName, const Plasma::DataEngine::Data& data) | ||||
Don't need to delete watcher because you constructed it with this as parent. https://doc.qt.io/qt-5/objecttrees.html
https://api.kde.org/frameworks/plasma-framework/html/classPlasma_1_1DataEngineConsumer.html davidre: Don't need to delete watcher because you constructed it with `this` as parent. https://doc.qt. | |||||
27 | { | ||||
28 | } | ||||
29 | | ||||
davidre: This method can be removed it's not referenced anywhere. | |||||
30 | QString PotdModule::getSource() | ||||
31 | { | ||||
32 | KConfigGroup group = config.group(QStringLiteral("Greeter")).group(QStringLiteral("Wallpaper")).group(QStringLiteral("org.kde.potd")).group(QStringLiteral("General")); | ||||
33 | QString provider = group.readEntry(QStringLiteral("Provider"), QString()); | ||||
34 | if (provider == QStringLiteral("unsplash")) { | ||||
35 | QString category = group.readEntry(QStringLiteral("Category"), QString()); | ||||
davidre: Why don't we care if the data was updated? | |||||
We only want to trigger the caching behavior of POTD data engine. No need to do anything with the data itself. guoyunhe: We only want to trigger the caching behavior of POTD data engine. No need to do anything with… | |||||
36 | return provider + QStringLiteral(":") + category; | ||||
37 | } else { | ||||
38 | return provider; | ||||
39 | } | ||||
40 | } | ||||
41 | | ||||
42 | #include "kded_potd.moc" | ||||
Couldn't we get the config directly with "kscreenlockerrc" if we use cascading either way? No need to seach for the actual path davidre: Couldn't we get the config directly with "kscreenlockerrc" if we use cascading either way? No… | |||||
guoyunhe: I tried but it doesn't work. | |||||
Maybe getProvider or getProviderName no to confuse it with the dataSource? davidre: Maybe getProvider or getProviderName no to confuse it with the dataSource? | |||||
davidre: Why? | |||||
It won't work without this line. Each time you change and save lockscreen configuration, the QFileSystemWatcher stop watching the configuration file. guoyunhe: It won't work without this line. Each time you change and save lockscreen configuration, the… |
QDebug