Changeset View
Standalone View
kdeds/potd/kded_potd.cpp
- This file was added.
1 | #include "kded_potd.h" | ||||
---|---|---|---|---|---|
2 | | ||||
3 | #include <QDebug> | ||||
4 | | ||||
davidre: QDebug | |||||
guoyunhe: Will remove. | |||||
5 | #include <Plasma/DataEngineConsumer> | ||||
6 | | ||||
7 | #include <kpluginfactory.h> | ||||
8 | #include <kpluginloader.h> | ||||
9 | | ||||
10 | #define COMPONENT_NAME "potd" | ||||
davidre: still leaks | |||||
11 | | ||||
davidre: unused | |||||
guoyunhe: Will remove. | |||||
12 | K_PLUGIN_FACTORY_WITH_JSON(PotdModuleFactory, | ||||
13 | "kded_potd.json", | ||||
davidre: You can use K_PLUGIN_CLASS_WITH_JSON | |||||
guoyunhe: Changed | |||||
14 | registerPlugin<PotdModule>();) | ||||
15 | | ||||
16 | PotdModule::PotdModule(QObject* parent, const QList<QVariant>&): KDEDModule(parent) | ||||
17 | { | ||||
18 | Plasma::DataEngineConsumer *consumer = new Plasma::DataEngineConsumer(); | ||||
19 | engine = consumer->dataEngine(QStringLiteral("potd")); | ||||
davidre: this leaks | |||||
guoyunhe: Fixed. | |||||
20 | configPath = QStandardPaths::locate(QStandardPaths::ConfigLocation, QStringLiteral("/kscreenlockerrc")); | ||||
21 | | ||||
22 | qDebug() << configPath; | ||||
23 | | ||||
24 | previousSource = getSource(); | ||||
25 | engine->connectSource(previousSource, this); | ||||
26 | | ||||
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 | watcher = new QFileSystemWatcher(this); | ||||
28 | watcher->addPath(configPath); | ||||
29 | connect(watcher, &QFileSystemWatcher::fileChanged, this, &PotdModule::fileChanged); | ||||
davidre: This method can be removed it's not referenced anywhere. | |||||
30 | } | ||||
31 | | ||||
32 | PotdModule::~PotdModule() | ||||
33 | { | ||||
34 | } | ||||
35 | | ||||
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 | void PotdModule::dataUpdated(const QString& sourceName, const Plasma::DataEngine::Data& data) | ||||
37 | { | ||||
38 | Q_UNUSED(sourceName); | ||||
39 | Q_UNUSED(data); | ||||
40 | } | ||||
41 | | ||||
42 | void PotdModule::fileChanged(const QString &path) | ||||
43 | { | ||||
44 | Q_UNUSED(path); | ||||
45 | engine->disconnectSource(previousSource, this); | ||||
46 | previousSource = getSource(); | ||||
47 | engine->connectSource(previousSource, this); | ||||
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… | |||||
48 | } | ||||
49 | | ||||
50 | QString PotdModule::getSource() | ||||
Maybe getProvider or getProviderName no to confuse it with the dataSource? davidre: Maybe getProvider or getProviderName no to confuse it with the dataSource? | |||||
51 | { | ||||
52 | KConfig config(configPath); | ||||
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. | |||||
53 | KConfigGroup group = config.group(QStringLiteral("Greeter")) | ||||
54 | .group(QStringLiteral("Wallpaper")) | ||||
55 | .group(QStringLiteral("org.kde.potd")) | ||||
56 | .group(QStringLiteral("General")); | ||||
57 | QString provider = group.readEntry(QStringLiteral("Provider"), QString()); | ||||
58 | if (provider == QStringLiteral("unsplash")) { | ||||
59 | QString category = group.readEntry(QStringLiteral("Category"), QString()); | ||||
60 | return provider + QStringLiteral(":") + category; | ||||
61 | } else { | ||||
62 | return provider; | ||||
63 | } | ||||
64 | } | ||||
65 | | ||||
66 | #include "kded_potd.moc" |
QDebug