diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ Archive Config CoreAddons + DBusAddons Declarative Holidays I18n @@ -76,6 +77,7 @@ ################# list the subdirectories ################# add_subdirectory(applets) add_subdirectory(dataengines) +add_subdirectory(kdeds) add_subdirectory(runners) add_subdirectory(wallpapers) diff --git a/dataengines/potd/PoTD-list.txt b/dataengines/potd/PoTD-list.txt --- a/dataengines/potd/PoTD-list.txt +++ b/dataengines/potd/PoTD-list.txt @@ -5,6 +5,7 @@ http://antwrp.gsfc.nasa.gov/apod/astropix.html Each day can be reached via the URL http://antwrp.gsfc.nasa.gov/apod/apYYMMDD.html where YY is the 2 digits year, MM is the 2 digits month and DD is the 2 digits day. +Note: sometimes, the webpage shows a YouTube video and picture cannot be fetched. * Flickr Interestingness ---------------------------- DONE http://www.flickr.com/explore/interesting/ diff --git a/dataengines/potd/cachedprovider.cpp b/dataengines/potd/cachedprovider.cpp --- a/dataengines/potd/cachedprovider.cpp +++ b/dataengines/potd/cachedprovider.cpp @@ -1,10 +1,10 @@ /* * Copyright (C) 2007 Tobias Koenig * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -51,13 +51,13 @@ void SaveImageThread::run() { const QString path = CachedProvider::identifierToPath( m_identifier ); - m_image.save(path, "PNG"); + m_image.save(path, "JPEG"); emit done( m_identifier, path, m_image ); } QString CachedProvider::identifierToPath( const QString &identifier ) { - const QString dataDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QLatin1String("/plasma_engine_potd/"); + const QString dataDir = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + QLatin1String("/plasma_engine_potd/"); QDir d; d.mkpath(dataDir); return dataDir + identifier; @@ -98,7 +98,7 @@ if (!QFile::exists( path ) ) { return false; } - + QRegularExpression re(QLatin1String(":\\d{4}-\\d{2}-\\d{2}")); if (!ignoreAge && !re.match(identifier).hasMatch()) { diff --git a/kdeds/CMakeLists.txt b/kdeds/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/kdeds/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(potd) diff --git a/kdeds/potd/CMakeLists.txt b/kdeds/potd/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/kdeds/potd/CMakeLists.txt @@ -0,0 +1,16 @@ +########### next target ############### + +set(dbus_interface_name org.kde.potd.xml) +set(kded_potd_PART_SRCS kded_potd.cpp) + +add_library(kded_potd MODULE ${kded_potd_PART_SRCS}) +set_target_properties(kded_potd PROPERTIES OUTPUT_NAME potd) + +target_link_libraries(kded_potd + KF5::DBusAddons + KF5::Plasma +) + +########### install files ############### +kcoreaddons_desktop_to_json(kded_potd kded_potd.desktop) +install(TARGETS kded_potd DESTINATION ${PLUGIN_INSTALL_DIR}/kf5/kded) diff --git a/kdeds/potd/README.md b/kdeds/potd/README.md new file mode 100644 --- /dev/null +++ b/kdeds/potd/README.md @@ -0,0 +1,8 @@ +# Picture Of The Day (POTD) Caching Daemon + +The lock screen runs in a special mode where it cannot access the internet. So +when it trys to load a POTD wallpaper that isn't cached, it fails. + +This daemon caches POTD before screen locking. The lock screen always loads POTD +from cache. Whenever the lock screen configuration changes, the daemon will read +the configuration and cache POTD if necessary. diff --git a/kdeds/potd/kded_potd.h b/kdeds/potd/kded_potd.h new file mode 100644 --- /dev/null +++ b/kdeds/potd/kded_potd.h @@ -0,0 +1,35 @@ +#ifndef _KDED_POTD_H_ +#define _KDED_POTD_H_ + +#include +#include +#include + +#include +#include +#include +#include +#include + +class PotdModule: public KDEDModule +{ + Q_OBJECT + +public: + PotdModule(QObject* parent, const QList&); + virtual ~PotdModule(); + +private Q_SLOTS: + void fileChanged(const QString &path); + +private: + QString getSource(); + + Plasma::DataEngineConsumer *consumer; + Plasma::DataEngine *engine; + QFileSystemWatcher *watcher; + QString configPath; + QString previousSource; +}; + +#endif diff --git a/kdeds/potd/kded_potd.cpp b/kdeds/potd/kded_potd.cpp new file mode 100644 --- /dev/null +++ b/kdeds/potd/kded_potd.cpp @@ -0,0 +1,61 @@ +#include "kded_potd.h" + +#include + +K_PLUGIN_CLASS_WITH_JSON(PotdModule, "kded_potd.json") + +PotdModule::PotdModule(QObject* parent, const QList&): KDEDModule(parent) +{ + 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); +} + +PotdModule::~PotdModule() +{ + delete consumer; +} + +void PotdModule::fileChanged(const QString &path) +{ + Q_UNUSED(path); + engine->disconnectSource(previousSource, this); + previousSource = getSource(); + 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. + watcher->addPath(configPath); +} + +QString PotdModule::getSource() +{ + KConfig config(configPath); + + KConfigGroup greeterGroup = config.group(QStringLiteral("Greeter")); + QString plugin = greeterGroup.readEntry(QStringLiteral("WallpaperPlugin"), QString()); + if (plugin != QStringLiteral("org.kde.potd")) { + return QStringLiteral(""); + } + + KConfigGroup potdGroup = greeterGroup + .group(QStringLiteral("Wallpaper")) + .group(QStringLiteral("org.kde.potd")) + .group(QStringLiteral("General")); + QString provider = potdGroup.readEntry(QStringLiteral("Provider"), QString()); + if (provider == QStringLiteral("unsplash")) { + QString category = potdGroup.readEntry(QStringLiteral("Category"), QString()); + return provider + QStringLiteral(":") + category; + } else { + return provider; + } +} + +#include "kded_potd.moc" diff --git a/kdeds/potd/kded_potd.desktop b/kdeds/potd/kded_potd.desktop new file mode 100644 --- /dev/null +++ b/kdeds/potd/kded_potd.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Name=Picture of The Day +Comment=Cache picture of the day for lock screen and SDDM +Type=Service +X-KDE-ServiceTypes=KDEDModule +X-KDE-Library=potd +X-KDE-Kded-autoload=true +OnlyShowIn=KDE;