kdeplasma-addons: move potd wallpaper to kde-workspace and reimplement it

nevermind the copyright flickr was busted and I rewrote it, pexels
provider was not even a thing before the fork

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-04-09 06:02:42 +03:00
parent 5f309a2b10
commit faa0514619
29 changed files with 0 additions and 2338 deletions

View file

@ -11,7 +11,6 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
endif()
add_subdirectory(applets)
add_subdirectory(dataengines)
add_subdirectory(runners)
add_subdirectory(wallpapers)

View file

@ -1 +0,0 @@
add_subdirectory(potd)

View file

@ -1,104 +0,0 @@
set(potd_engine_SRCS
cachedprovider.cpp
potd.cpp
)
kde4_add_plugin(plasma_engine_potd ${potd_engine_SRCS})
target_link_libraries(plasma_engine_potd
KDE4::kdeui
KDE4::plasma
plasmapotdprovidercore
)
install(
TARGETS plasma_engine_potd
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
)
install(
FILES plasma-dataengine-potd.desktop
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
)
########### plugin core library ############
set(potd_provider_core_SRCS
potdprovider.cpp
)
add_library(plasmapotdprovidercore SHARED ${potd_provider_core_SRCS})
target_link_libraries(plasmapotdprovidercore KDE4::kdeui)
generate_export_header(plasmapotdprovidercore BASE_NAME plasma_potd)
install(
TARGETS plasmapotdprovidercore
DESTINATION ${KDE4_LIB_INSTALL_DIR}
)
install(
FILES plasma_potdprovider.desktop
DESTINATION ${KDE4_SERVICETYPES_INSTALL_DIR}
)
########### plugins ###############
set( potd_flickr_provider_SRCS
flickrprovider.cpp
)
kde4_add_plugin(plasma_potd_flickrprovider ${potd_flickr_provider_SRCS})
target_link_libraries(plasma_potd_flickrprovider
KDE4::kio
KDE4::kdecore
${QT_QTGUI_LIBRARY}
plasmapotdprovidercore
)
install(
TARGETS plasma_potd_flickrprovider
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
)
install(
FILES flickrprovider.desktop
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
)
set(potd_apod_provider_SRCS
apodprovider.cpp
)
kde4_add_plugin(plasma_potd_apodprovider ${potd_apod_provider_SRCS})
target_link_libraries(plasma_potd_apodprovider
KDE4::kio
KDE4::kdecore
${QT_QTGUI_LIBRARY}
plasmapotdprovidercore
)
install(
TARGETS plasma_potd_apodprovider
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
)
install(
FILES apodprovider.desktop
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
)
set(potd_pexels_provider_SRCS
pexelsprovider.cpp
)
kde4_add_plugin(plasma_potd_pexelsprovider ${potd_pexels_provider_SRCS})
target_link_libraries(plasma_potd_pexelsprovider
KDE4::kio
KDE4::kdecore
${QT_QTGUI_LIBRARY}
plasmapotdprovidercore
)
install(
TARGETS plasma_potd_pexelsprovider
DESTINATION ${KDE4_PLUGIN_INSTALL_DIR}
)
install(
FILES pexelsprovider.desktop
DESTINATION ${KDE4_SERVICES_INSTALL_DIR}
)

View file

@ -1,20 +0,0 @@
HOW TO ADD A NEW PICTURE OF THE DAY AND HOW TO USE THE ENGINE
- in the data engine "apod"
Add your provider in the Potd class, updateSource( const QString &identifier ) method
- in the applet, you get a QImage and you can call the provider with
Plasma::DataEngine *engine = dataEngine( "potd" );
QDate mCurrentDate = QDate::currentDate();
const QString identifier = QString("apod") + ":" + mCurrentDate.toString( Qt::ISODate );
engine->disconnectSource( identifier, this );
engine->connectSource( identifier, this );
const Plasma::DataEngine::Data data = engine->query( identifier );
QImage mImage = data[ identifier ].value<QImage>();
- TO DEBUG your new provider you need to comment the lines about caching the pic in
potd.cpp at the beginning of the
bool PotdEngine::updateSource( const QString &identifier )
method.

View file

@ -1,54 +0,0 @@
LIST OF POSSIBLE PROVIDERS
--------------------------
* NASA Astronomy Picture of the Day (APOD) ----------- DONE
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.
* Flickr Interestingness ---------------------------- DONE
http://www.flickr.com/explore/interesting/
API http://www.flickr.com/services/api/flickr.interestingness.getList.html
* Botanical PoTD
http://www.ubcbotanicalgarden.org/potd/
* EPOD - Earth Science Picture of the Day ----------- DONE
http://epod.usra.edu/
RSS feed http://interglacial.com/rss/epod.rss
* OSEI (Operational Significant Event Imagery)
Image Of the Day ------------------------------------- DONE
http://www.osei.noaa.gov/OSEIiod.html
* WCPoTD Wikimedia Commons Picture of The Day ---------- almost DONE (need to add the Credits URL below the pic)
http://tools.wikimedia.de/~daniel/potd/potd.php
http://en.wikipedia.org/wiki/Wikipedia:Picture_of_the_day#Including_the_POTD_on_your_user_page
http://en.wikipedia.org/w/index.php?title=Template:POTD/2008-02-03&action=render
Feed for Commons Featured Pictures
http://tools.wikimedia.de/~magnus/catfood.php?category=Featured_pictures
* http://interfacelift.com/wallpaper/
RSS feed: http://feeds.feedburner.com/InterfaceliftNewestWallpaper
* HackADay.com
http://www.hackaday.com/
RSS: http://www.hackaday.com/rss.xml
* Radiology Picture of the Day
http://www.radpod.org/
* Taiwan Picture of the Day
http://fotozon.com/daily/taiwan/
* Space.com Image of the day
http://www.space.com/imageoftheday/
* Animal of the Day
http://www.thewebsiteofeverything.com/weblog/
http://archive.dailypicture.net/animal_picture_of_the_day__daily_animal_photograph.htm
* A list of PoTD:
http://www.w3streams.com/

View file

@ -1,102 +0,0 @@
/*
* Copyright (C) 2007 Tobias Koenig <tokoe@kde.org>
* Copyright 2008 by Anne-Marie Mahfouf <annma@kde.org>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "apodprovider.h"
#include <QtCore/QRegExp>
#include <QtGui/QImage>
#include <KDebug>
#include <kio/job.h>
POTDPROVIDER_EXPORT_PLUGIN(ApodProvider, "ApodProvider", "")
class ApodProvider::Private
{
public:
Private(ApodProvider *parent)
: mParent(parent)
{
}
void pageRequestFinished(KJob*);
void imageRequestFinished(KJob*);
void parsePage();
ApodProvider *mParent;
QImage mImage;
};
void ApodProvider::Private::pageRequestFinished(KJob *_job)
{
KIO::StoredTransferJob *job = static_cast<KIO::StoredTransferJob*>(_job);
if (job->error()) {
emit mParent->error(mParent);
return;
}
const QByteArray jobdata = job->data();
const QString data = QString::fromUtf8(jobdata.constData(), jobdata.size());
const QString pattern(QLatin1String("<a href=\"(image/.*)\""));
QRegExp exp( pattern );
exp.setMinimal(true);
if (exp.indexIn(data) != -1) {
const QString sub = exp.cap(1);
KUrl url(QString::fromLatin1("https://antwrp.gsfc.nasa.gov/apod/%1").arg(sub));
KIO::StoredTransferJob *imageJob = KIO::storedGet(url, KIO::HideProgressInfo);
mParent->connect(imageJob, SIGNAL(finished(KJob*)), SLOT(imageRequestFinished(KJob*)));
} else {
emit mParent->error(mParent);
}
}
void ApodProvider::Private::imageRequestFinished(KJob *_job )
{
KIO::StoredTransferJob *job = static_cast<KIO::StoredTransferJob*>(_job);
if (job->error()) {
emit mParent->error(mParent);
return;
}
mImage = QImage::fromData(job->data());
emit mParent->finished( mParent );
}
ApodProvider::ApodProvider(QObject *parent, const QVariantList &args)
: PotdProvider(parent, args),
d(new Private(this))
{
KUrl url(QString::fromLatin1("https://antwrp.gsfc.nasa.gov/apod/"));
KIO::StoredTransferJob *job = KIO::storedGet(url, KIO::HideProgressInfo);
connect(job, SIGNAL(finished(KJob*)), SLOT(pageRequestFinished(KJob*)));
}
ApodProvider::~ApodProvider()
{
delete d;
}
QImage ApodProvider::image() const
{
return d->mImage;
}
#include "moc_apodprovider.cpp"

View file

@ -1,104 +0,0 @@
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=PlasmaPoTD/Plugin
X-KDE-Library=plasma_potd_apodprovider
X-KDE-PlasmaPoTDProvider-Identifier=apod
Icon=
Name=Astronomy Picture of the Day
Name[ar]=الصورة الفضائية اليومية
Name[bs]=Astronomska slika dana
Name[ca]=Imatge astronòmica del dia
Name[ca@valencia]=Imatge astronòmica del dia
Name[cs]=Obrázek dne z Astronomie
Name[da]=Dagens astronomibillede
Name[de]=Bild des Tages der Astronomie
Name[el]=Αστρονομική φωτογραφία της ημέρας
Name[en_GB]=Astronomy Picture of the Day
Name[es]=Imagen astronómica del día
Name[et]=Astronoomia päevapilt
Name[fi]=Päivän tähtitiedekuva
Name[fr]=Image du jour d'astronomie
Name[ga]=Grianghraf Réalteolaíochta an Lae
Name[gl]=Imaxe do día de astronomía
Name[hr]=Slika dana na Astronomy
Name[hu]=A nap csillagászati képe
Name[it]=Astronomy Picture of the Day
Name[ja]=
Name[kk]=Астрономиялық "Тәулік суреті" (Apod)
Name[km]= Astronomy
Name[ko]=
Name[lv]=Astronomijas dienas attēls
Name[mr]= ि ि
Name[nb]=Dagens astronomibilde
Name[nds]=Astronoomsch Bild för Vundaag
Name[nl]=Astronomische afbeelding van de dag
Name[nn]=Dagens astronomibilete
Name[pa]=
Name[pl]=Astronomiczny obraz dnia
Name[pt]=Imagem do Dia na Astronomia
Name[pt_BR]=Imagem astronômica do dia
Name[ro]=Imaginea zilei din astronomie
Name[ru]=Астрономический снимок дня
Name[sk]=Obrázok dňa z Astronómie
Name[sl]=Astronomska slika dneva
Name[sr]=астрономска слика дана
Name[sr@ijekavian]=астрономска слика дана
Name[sr@ijekavianlatin]=astronomska slika dana
Name[sr@latin]=astronomska slika dana
Name[sv]=Dagens astronomiska bild
Name[th]=
Name[tr]=Günün Astronomik Fotoğrafı
Name[uk]=Зображення дня Astronomy
Name[x-test]=xxAstronomy Picture of the Dayxx
Name[zh_CN]=()
Name[zh_TW]=
Comment=Apod Provider
Comment[ar]=المزود Apod
Comment[ast]=Fornidor d'Apod
Comment[bs]=Dobavljač Apod-a
Comment[ca]=Proveïdor Apod
Comment[ca@valencia]=Proveïdor Apod
Comment[cs]=Poskytovatel Apodu
Comment[da]=Apod-udbyder.
Comment[de]=Apod-Anbieter
Comment[el]=Πάροχος Apod
Comment[en_GB]=Apod Provider
Comment[es]=Proveedor de Apod
Comment[et]=Apodi pakkuja
Comment[fi]=Apod-tarjoaja
Comment[fr]=Fournisseur « APOD »
Comment[ga]=Soláthraí Apod
Comment[gl]=Fornecedor de Apod
Comment[hr]=Pružatelj Apoda
Comment[hu]=Apod-szolgáltató
Comment[is]=Apod þjónusta
Comment[it]=Fornitore Apod
Comment[ja]=Apod
Comment[kk]=Apod таратушысы
Comment[km]= Apod
Comment[ko]=
Comment[lt]=Apod tiekėjas
Comment[lv]=Apod piegādātājs
Comment[mr]= ि
Comment[nb]=Apod-leverandør
Comment[nds]=ABifV-Anbeder
Comment[nl]=Apod-provider
Comment[nn]=Apod-tilbydar
Comment[pl]=Usługodawca Apod
Comment[pt]=Fornecedor do Apod
Comment[pt_BR]=Fornecedor Apod
Comment[ro]=Furnizor Apod
Comment[ru]=Источник данных Apod
Comment[sk]=Poskytovateľ Apod
Comment[sl]=Ponudnik Apod
Comment[sr]=Добављач АПОДа
Comment[sr@ijekavian]=Добављач АПОДа
Comment[sr@ijekavianlatin]=Dobavljač APODa
Comment[sr@latin]=Dobavljač APODa
Comment[sv]=Tillhandahåll från Apod
Comment[tr]=Apod Sağlayıcı
Comment[uk]=Постачальник даних Apod
Comment[x-test]=xxApod Providerxx
Comment[zh_CN]=Apod
Comment[zh_TW]=Apod

View file

@ -1,69 +0,0 @@
/*
* Copyright (C) 2007 Tobias Koenig <tokoe@kde.org>
* Copyright 2008 by Anne-Marie Mahfouf <annma@kde.org>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef APODPROVIDER_H
#define APODPROVIDER_H
#include "potdprovider.h"
/**
* This class provides the image for APOD
* "Astronomy Picture Of the Day"
* located at http://antwrp.gsfc.nasa.gov/apod.
* Direct link to the picture of the day page is
* http://antwrp.gsfc.nasa.gov/apod/apYYMMDD.html
* where YY is the year last 2 digits,
* MM is the month and DD the day, in 2 digits.
*/
class ApodProvider : public PotdProvider
{
Q_OBJECT
public:
/**
* Creates a new APOD provider.
*
* @param date The date for which the image shall be fetched.
* @param parent The parent object.
*/
ApodProvider( QObject *parent, const QVariantList &args );
/**
* Destroys the APOD provider.
*/
~ApodProvider();
/**
* Returns the requested image.
*
* Note: This method returns only a valid image after the
* finished() signal has been emitted.
*/
virtual QImage image() const;
private:
class Private;
Private* const d;
Q_PRIVATE_SLOT( d, void pageRequestFinished( KJob* ) )
Q_PRIVATE_SLOT( d, void imageRequestFinished( KJob* ) )
};
#endif

View file

@ -1,113 +0,0 @@
/*
* Copyright (C) 2007 Tobias Koenig <tokoe@kde.org>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "cachedprovider.h"
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QTimer>
#include <QtCore/QThreadPool>
#include <QtGui/QImage>
#include <QtGui/QImageWriter>
#include <kdebug.h>
#include <kstandarddirs.h>
static const QByteArray imageFormat = QImageWriter::defaultImageFormat();
LoadImageThread::LoadImageThread(const QString &filePath)
: m_filePath(filePath)
{
}
void LoadImageThread::run()
{
QImage image;
image.load(m_filePath, imageFormat);
emit done(image);
}
SaveImageThread::SaveImageThread(const QString &identifier, const QImage &image)
: m_image(image),
m_identifier(identifier)
{
}
void SaveImageThread::run()
{
const QString path = CachedProvider::identifierToPath( m_identifier );
m_image.save(path, imageFormat);
emit done( m_identifier, path, m_image );
}
QString CachedProvider::identifierToPath( const QString &identifier )
{
const QString dataDir = KStandardDirs::locateLocal( "cache", QLatin1String("plasma_engine_podt/") );
return QString( dataDir + identifier );
}
CachedProvider::CachedProvider( const QString &identifier, QObject *parent )
: PotdProvider( parent ), mIdentifier( identifier )
{
LoadImageThread *thread = new LoadImageThread( identifierToPath( mIdentifier ) );
connect(thread, SIGNAL(done(QImage)), this, SLOT(triggerFinished(QImage)));
QThreadPool::globalInstance()->start(thread);
}
CachedProvider::~CachedProvider()
{
}
QImage CachedProvider::image() const
{
return mImage;
}
QString CachedProvider::identifier() const
{
return mIdentifier;
}
void CachedProvider::triggerFinished(const QImage &image)
{
mImage = image;
emit finished( this );
}
bool CachedProvider::isCached( const QString &identifier, bool ignoreAge )
{
const QString path = identifierToPath( identifier );
if (!QFile::exists( path ) ) {
return false;
}
if (!ignoreAge && !identifier.contains( ':' ) ) {
// no date in the identifier, so it's a daily; check to see ifthe modification time is today
QFileInfo info( path );
if ( info.lastModified().daysTo( QDateTime::currentDateTime() ) > 1 ) {
return false;
}
}
return true;
}
#include "moc_cachedprovider.cpp"

View file

@ -1,111 +0,0 @@
/*
* Copyright (C) 2007 Tobias Koenig <tokoe@kde.org>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef CACHEDPROVIDER_H
#define CACHEDPROVIDER_H
#include <QImage>
#include <QRunnable>
#include "potdprovider.h"
/**
* This class provides pictures from the local cache.
*/
class CachedProvider : public PotdProvider
{
Q_OBJECT
public:
/**
* Creates a new cached provider.
*
* @param identifier The identifier of the cached picture.
* @param parent The parent object.
*/
CachedProvider( const QString &identifier, QObject *parent );
/**
* Destroys the cached provider.
*/
~CachedProvider();
/**
* Returns the requested image.
*
* Note: This method returns only a valid image after the
* finished() signal has been emitted.
*/
virtual QImage image() const;
/**
* Returns the identifier of the picture request (name + date).
*/
virtual QString identifier() const;
/**
* Returns whether a picture with the given @p identifier is cached.
*/
static bool isCached( const QString &identifier, bool ignoreAge = false );
/**
* Returns a path for the given identifier
*/
static QString identifierToPath( const QString &identifier );
private Q_SLOTS:
void triggerFinished(const QImage &image);
private:
QString mIdentifier;
QImage mImage;
};
class LoadImageThread : public QObject, public QRunnable
{
Q_OBJECT
public:
LoadImageThread(const QString &filePath);
void run();
Q_SIGNALS:
void done(const QImage &pixmap);
private:
QString m_filePath;
};
class SaveImageThread : public QObject, public QRunnable
{
Q_OBJECT
public:
SaveImageThread(const QString &identifier, const QImage &image);
void run();
Q_SIGNALS:
void done( const QString &source, const QString &path, const QImage &img );
private:
QImage m_image;
QString m_identifier;
};
#endif

View file

@ -1,171 +0,0 @@
/*
* Copyright (C) 2007 Tobias Koenig <tokoe@kde.org>
* Copyright 2008 by Anne-Marie Mahfouf <annma@kde.org>
* Copyright 2008 by Georges Toth <gtoth@trypill.org>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "flickrprovider.h"
#include <QImage>
#include <QJsonDocument>
#include <KDebug>
#include <KRandom>
#include <kio/job.h>
// for reference:
// https://www.flickr.com/services/api/misc.urls.html
// https://www.flickr.com/services/api/explore/flickr.interestingness.getList
static const QString s_flickrapiurl = QString::fromLatin1(
"https://api.flickr.com/services/rest/?api_key=31f4917c363e2f76b9fc944790dcc338&format=json&method=flickr.interestingness.getList&date="
);
static const QString s_flickrimageurl = QString::fromLatin1(
"https://live.staticflickr.com/%1/%2_%3_b.jpg"
);
POTDPROVIDER_EXPORT_PLUGIN(FlickrProvider, "FlickrProvider", "")
class FlickrProvider::Private
{
public:
Private(FlickrProvider *parent)
: mParent(parent)
{
}
void pageRequestFinished(KJob*);
void imageRequestFinished(KJob*);
void parsePage();
FlickrProvider *mParent;
QDate mActualDate;
QImage mImage;
private:
QStringList m_photoList;
};
void FlickrProvider::Private::pageRequestFinished(KJob *kjob)
{
KIO::StoredTransferJob* kstoredjob = qobject_cast<KIO::StoredTransferJob*>(kjob);
if (kstoredjob->error()) {
kWarning() << "request error" << kstoredjob->url();
kstoredjob->deleteLater();
emit mParent->error(mParent);
return;
}
m_photoList.clear();
// HACK: fix the data to be valid JSON
QByteArray jsondata = kstoredjob->data();
if (jsondata.startsWith("jsonFlickrApi(") && jsondata.endsWith(')')) {
jsondata = jsondata.mid(14, jsondata.size() - 15);
}
kstoredjob->deleteLater();
const QJsonDocument jsondoc = QJsonDocument::fromJson(jsondata);
if (jsondoc.isNull()) {
kWarning() << "JSON error" << jsondoc.errorString();
return;
}
const QVariantMap jsonmap = jsondoc.toVariant().toMap();
const QString apistat = jsonmap["stat"].toString();
if (apistat == QLatin1String("fail")) {
// No pictures available for the specified parameters, decrement the date to two days earlier...
mActualDate = mActualDate.addDays(-2);
const KUrl queryurl(s_flickrapiurl + mActualDate.toString(Qt::ISODate));
kDebug() << "stat fail, retrying with" << queryurl.prettyUrl();
kstoredjob->deleteLater();
kstoredjob = KIO::storedGet(queryurl, KIO::HideProgressInfo);
kstoredjob->setAutoDelete(false);
mParent->connect(kstoredjob, SIGNAL(finished(KJob*)), SLOT(pageRequestFinished(KJob*)));
return;
}
foreach (const QVariant &photo, jsonmap["photos"].toMap()["photo"].toList()) {
const QVariantMap photomap = photo.toMap();
const QString photoispublic = photomap["ispublic"].toString();
if (photoispublic != QLatin1String("1")) {
kDebug() << "skipping non-public photo";
continue;
}
const QString photoserver = photomap["server"].toString();
const QString photoid = photomap["id"].toString();
const QString photosecret = photomap["secret"].toString();
const QString photourl = s_flickrimageurl.arg(photoserver, photoid, photosecret);
kDebug() << "photo" << photourl;
m_photoList.append(photourl);
}
if (m_photoList.isEmpty()) {
kWarning() << "empty photo list";
return;
}
const KUrl photourl(m_photoList.at(KRandom::randomMax(m_photoList.size())));
kDebug() << "chosen photo" << photourl.prettyUrl();
kstoredjob = KIO::storedGet(photourl, KIO::HideProgressInfo);
kstoredjob->setAutoDelete(false);
mParent->connect(kstoredjob, SIGNAL(finished(KJob*)), SLOT(imageRequestFinished(KJob*)));
}
void FlickrProvider::Private::imageRequestFinished(KJob *kjob)
{
KIO::StoredTransferJob* kstoredjob = qobject_cast<KIO::StoredTransferJob*>(kjob);
if (kstoredjob->error()) {
kWarning() << "image job error" << kstoredjob->url();
kstoredjob->deleteLater();
emit mParent->error(mParent);
return;
}
mImage = QImage::fromData(kstoredjob->data());
if (mImage.isNull()) {
kWarning() << "null image for" << kstoredjob->url();
}
kstoredjob->deleteLater();
emit mParent->finished(mParent);
}
FlickrProvider::FlickrProvider(QObject *parent, const QVariantList &args)
: PotdProvider(parent, args),
d(new Private(this))
{
d->mActualDate = date();
const KUrl queryurl(s_flickrapiurl + d->mActualDate.toString(Qt::ISODate));
kDebug() << "starting job for" << queryurl.prettyUrl();
KIO::StoredTransferJob *kstoredjob = KIO::storedGet(queryurl, KIO::HideProgressInfo);
kstoredjob->setAutoDelete(false);
connect(kstoredjob, SIGNAL(finished(KJob*)), SLOT(pageRequestFinished(KJob*)));
}
FlickrProvider::~FlickrProvider()
{
delete d;
}
QImage FlickrProvider::image() const
{
return d->mImage;
}
#include "moc_flickrprovider.cpp"

View file

@ -1,106 +0,0 @@
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=PlasmaPoTD/Plugin
X-KDE-Library=plasma_potd_flickrprovider
X-KDE-PlasmaPoTDProvider-Identifier=flickr
Icon=
Name=Flickr Picture of the Day
Name[ar]=صورة فليكر اليومية
Name[bs]=Flickr slika dana
Name[ca]=Imatge Flickr del dia
Name[ca@valencia]=Imatge Flickr del dia
Name[cs]=Obrázek dne z Flickru
Name[da]=Dagens Flickr-billede
Name[de]=Bild des Tages von Flickr
Name[el]=Flickr φωτογραφία της ημέρας
Name[en_GB]=Flickr Picture of the Day
Name[es]=Imagen de Flickr del día
Name[et]=Flickri päevapilt
Name[fi]=Päivän Flickr-kuva
Name[fr]=Image du jour « Flickr »
Name[ga]=Grianghraf an Lae ó Flickr
Name[gl]=Imaxe do día de Flickr
Name[hr]=Slika dana na Flickru
Name[hu]=A nap képe a Flickr-ön
Name[it]=Immagine del giorno di Flickr
Name[ja]=Flickr
Name[kk]=Flickr "Тәулік суреті" (Apod)
Name[km]= Flickr
Name[ko]= Flickr
Name[lv]=Flickr dienas attēls
Name[mr]=ि ि ि
Name[nb]=Dagens Flickr-bilde
Name[nds]=Flickr-Bild för Vundaag
Name[nl]=Flickr-afbeelding van de dag
Name[nn]=Dagens bilete frå Flickr
Name[pa]=ਿ
Name[pl]=Obraz dnia Flickr
Name[pt]=Imagem do Dia no Flickr
Name[pt_BR]=Imagem do dia do Flickr
Name[ro]=Imaginea zilei de pe Flickr
Name[ru]=Изображение дня Flickr
Name[sk]=Obrázok dňa z Flickr
Name[sl]=Flickr-jeva slika dneva
Name[sr]=слика дана са Фликра
Name[sr@ijekavian]=слика дана са Фликра
Name[sr@ijekavianlatin]=slika dana sa Flickra
Name[sr@latin]=slika dana sa Flickra
Name[sv]=Dagens bild från Flickr
Name[th]= Flickr
Name[tr]=Günün Flickr Resmi
Name[uk]=Зображення дня Flickr
Name[x-test]=xxFlickr Picture of the Dayxx
Name[zh_CN]=(Flickr)
Name[zh_TW]= Flickr
Comment=Flickr Provider
Comment[ar]=الموزد Flickr
Comment[ast]=Fornidor de Flickr
Comment[bs]=Dobavljac Flickr-a
Comment[ca]=Proveïdor Flickr
Comment[ca@valencia]=Proveïdor Flickr
Comment[cs]=Poskytovatel Flickru
Comment[da]=Flickr-udbyder.
Comment[de]=Flickr-Anbieter
Comment[el]=Πάροχος Flickr
Comment[en_GB]=Flickr Provider
Comment[es]=Proveedor de Flickr
Comment[et]=Flickri pakkuja
Comment[fi]=Flickr-tarjoaja
Comment[fr]=Fournisseur « Flickr »
Comment[ga]=Soláthraí Flickr
Comment[gl]=Fornecedor de Flickr
Comment[hr]=Pružatelj Flickra
Comment[hu]=Flickr-szolgáltató
Comment[is]=Flickr þjónusta
Comment[it]=Fornitore Flickr
Comment[ja]=Flickr
Comment[kk]=Flickr таратушысы
Comment[km]= Flickr
Comment[ko]=Flickr
Comment[lt]=Flickr tiekėjas
Comment[lv]=Flickr piegādātājs
Comment[mr]=ि
Comment[nb]=Flickr-leverandør
Comment[nds]=Flickr-Anbeder
Comment[nl]=Flickr-provider
Comment[nn]=Flickr-tilbydar
Comment[pa]=ਿ
Comment[pl]=Usługodawca Flickr
Comment[pt]=Fornecedor do Flickr
Comment[pt_BR]=Fornecedor Flickr
Comment[ro]=Furnizor Flickr
Comment[ru]=Источник данных Flickr
Comment[sk]=Poskytovateľ Flickr
Comment[sl]=Ponudnik Flickr
Comment[sr]=Добављач Фликра
Comment[sr@ijekavian]=Добављач Фликра
Comment[sr@ijekavianlatin]=Dobavljač Flickra
Comment[sr@latin]=Dobavljač Flickra
Comment[sv]=Tillhandahåll från Flickr
Comment[tr]=Flickr Sağlayıcı
Comment[uk]=Постачальник даних Flickr
Comment[wa]=Ahesseu d' Flickr
Comment[x-test]=xxFlickr Providerxx
Comment[zh_CN]=Flickr
Comment[zh_TW]=Flickr

View file

@ -1,66 +0,0 @@
/*
* Copyright (C) 2007 Tobias Koenig <tokoe@kde.org>
* Copyright 2008 by Anne-Marie Mahfouf <annma@kde.org>
* Copyright 2008 by Georges Toth <gtoth@trypill.org>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef FLICKRPROVIDER_H
#define FLICKRPROVIDER_H
#include "potdprovider.h"
/**
* This class grabs a random image from the flickr
* interestingness stream of pictures, for the given date.
* Should there be no image for the current date, it tries
* to grab one from the day before yesterday.
*/
class FlickrProvider : public PotdProvider
{
Q_OBJECT
public:
/**
* Creates a new flickr provider.
*
* @param date The date for which the image shall be fetched.
* @param parent The parent object.
*/
FlickrProvider(QObject *parent, const QVariantList &args);
/**
* Destroys the flickr provider.
*/
~FlickrProvider();
/**
* Returns the requested image.
*
* Note: This method returns only a valid image after the
* finished() signal has been emitted.
*/
virtual QImage image() const;
private:
class Private;
Private* const d;
Q_PRIVATE_SLOT(d, void pageRequestFinished(KJob* ))
Q_PRIVATE_SLOT(d, void imageRequestFinished(KJob*))
};
#endif

View file

@ -1,143 +0,0 @@
/*
* Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "pexelsprovider.h"
#include <QImage>
#include <QJsonDocument>
#include <KDebug>
#include <KRandom>
#include <kio/job.h>
// for reference:
// https://www.pexels.com/api/documentation/#photos-curated
static const QString s_pexelsapikey = QString::fromLatin1("WeDUAEYr4oV9211fAie7Jcwat6tNlkrW0BTx7kaoiyITGWp7WMcxpSoM");
static const QString s_pexelsapiurl = QString::fromLatin1("https://api.pexels.com/v1/curated");
POTDPROVIDER_EXPORT_PLUGIN(PexelsProvider, "PexelsProvider", "")
class PexelsProvider::Private
{
public:
Private(PexelsProvider *parent)
: mParent(parent)
{
}
void pageRequestFinished(KJob*);
void imageRequestFinished(KJob*);
void parsePage();
PexelsProvider *mParent;
QImage mImage;
private:
QStringList m_photoList;
};
void PexelsProvider::Private::pageRequestFinished(KJob *kjob)
{
KIO::StoredTransferJob* kstoredjob = qobject_cast<KIO::StoredTransferJob*>(kjob);
if (kstoredjob->error()) {
kWarning() << "request error" << kstoredjob->url();
kstoredjob->deleteLater();
emit mParent->error(mParent);
return;
}
m_photoList.clear();
const QByteArray jsondata = kstoredjob->data();
kstoredjob->deleteLater();
const QJsonDocument jsondoc = QJsonDocument::fromJson(jsondata);
if (jsondoc.isNull()) {
kWarning() << "JSON error" << jsondoc.errorString();
return;
}
const QVariantMap jsonmap = jsondoc.toVariant().toMap();
const QVariantList jsonphotoslist = jsonmap["photos"].toList();
foreach (const QVariant &photo, jsonphotoslist) {
const QVariantMap photomap = photo.toMap()["src"].toMap();
const QString photourl = photomap["landscape"].toString();
if (photourl.isEmpty()) {
kDebug() << "skipping photo without landscape url";
continue;
}
kDebug() << "photo" << photourl;
m_photoList.append(photourl);
}
if (m_photoList.isEmpty()) {
kWarning() << "empty photo list";
return;
}
const KUrl photourl(m_photoList.at(KRandom::randomMax(m_photoList.size())));
kDebug() << "chosen photo" << photourl.prettyUrl();
kstoredjob = KIO::storedGet(photourl, KIO::HideProgressInfo);
kstoredjob->setAutoDelete(false);
kstoredjob->addMetaData("Authorization", s_pexelsapikey);
mParent->connect(kstoredjob, SIGNAL(finished(KJob*)), SLOT(imageRequestFinished(KJob*)));
}
void PexelsProvider::Private::imageRequestFinished(KJob *kjob)
{
KIO::StoredTransferJob* kstoredjob = qobject_cast<KIO::StoredTransferJob*>(kjob);
if (kstoredjob->error()) {
kWarning() << "image job error" << kstoredjob->url();
kstoredjob->deleteLater();
emit mParent->error(mParent);
return;
}
mImage = QImage::fromData(kstoredjob->data());
if (mImage.isNull()) {
kWarning() << "null image for" << kstoredjob->url();
}
kstoredjob->deleteLater();
emit mParent->finished(mParent);
}
PexelsProvider::PexelsProvider(QObject *parent, const QVariantList &args)
: PotdProvider(parent, args),
d(new Private(this))
{
const KUrl queryurl(s_pexelsapiurl);
kDebug() << "starting job for" << queryurl.prettyUrl();
KIO::StoredTransferJob *kstoredjob = KIO::storedGet(queryurl, KIO::HideProgressInfo);
kstoredjob->setAutoDelete(false);
kstoredjob->addMetaData("Authorization", s_pexelsapikey);
connect(kstoredjob, SIGNAL(finished(KJob*)), SLOT(pageRequestFinished(KJob*)));
}
PexelsProvider::~PexelsProvider()
{
delete d;
}
QImage PexelsProvider::image() const
{
return d->mImage;
}
#include "moc_pexelsprovider.cpp"

View file

@ -1,9 +0,0 @@
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=PlasmaPoTD/Plugin
X-KDE-Library=plasma_potd_pexelsprovider
X-KDE-PlasmaPoTDProvider-Identifier=pexels
Icon=
Name=Pexels Picture of the Day
Comment=Pexels Provider

View file

@ -1,42 +0,0 @@
/*
* Copyright (C) 2023 Ivailo Monev <xakepa10@gmail.com>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PEXELSPROVIDER_H
#define PEXELSPROVIDER_H
#include "potdprovider.h"
class PexelsProvider : public PotdProvider
{
Q_OBJECT
public:
PexelsProvider(QObject *parent, const QVariantList &args);
~PexelsProvider();
virtual QImage image() const;
private:
class Private;
Private* const d;
Q_PRIVATE_SLOT(d, void pageRequestFinished(KJob *))
Q_PRIVATE_SLOT(d, void imageRequestFinished(KJob *))
};
#endif

View file

@ -1,112 +0,0 @@
[Desktop Entry]
Encoding=UTF-8
Name=Picture of the Day
Name[ar]=صورة اليوم
Name[ast]=Imaxe del día
Name[bs]=Slika dana
Name[ca]=Imatge del dia
Name[ca@valencia]=Imatge del dia
Name[cs]=Obrázek dne
Name[da]=Dagens billede
Name[de]=Bild des Tages
Name[el]=Φωτογραφία της ημέρας
Name[en_GB]=Picture of the Day
Name[es]=Imagen del día
Name[et]=Päevapilt
Name[fi]=Päivän kuva
Name[fr]=Image du jour
Name[ga]=Grianghraf an Lae
Name[gl]=Imaxe do día
Name[hr]=Slika dana
Name[hu]=A nap képe
Name[is]=Myndir dagsins
Name[it]=Immagine del giorno
Name[ja]=
Name[kk]=Тәулік суреті
Name[km]=
Name[ko]=
Name[lt]=Dienos paveiksliukas
Name[lv]=Dienas attēls
Name[mr]=ि ि
Name[nb]=Dagens bilde
Name[nds]=Bild för Vundaag
Name[nl]=Afbeelding van de dag
Name[nn]=Dagens bilete
Name[pa]=
Name[pl]=Obraz dnia
Name[pt]=Imagem do Dia
Name[pt_BR]=Imagem do dia
Name[ro]=Imaginea zilei
Name[ru]=Изображение дня
Name[sk]=Obrázok dňa
Name[sl]=Slika dneva
Name[sr]=слика дана
Name[sr@ijekavian]=слика дана
Name[sr@ijekavianlatin]=slika dana
Name[sr@latin]=slika dana
Name[sv]=Dagens bild
Name[tr]=Günün Resmi
Name[uk]=Картинка дня
Name[wa]=Imådje do djoû
Name[x-test]=xxPicture of the Dayxx
Name[zh_CN]=
Name[zh_TW]=
Comment=Data Engine for getting various online Pictures of The Day.
Comment[ar]=محرك بيانات للحصول على مختلف صور هذا اليوم من الإنترنت.
Comment[ast]=Motor de datos pa obtener delles imáxenes del día de la rede.
Comment[bs]=Pogon podataka za dobivanje različitih slika dana sa veze
Comment[ca]=Motor de dades per accedir a diverses «imatges del dia» en línia.
Comment[ca@valencia]=Motor de dades per accedir a diverses «imatges del dia» en línia.
Comment[cs]=Mechanismus pro získávání různých obrázků dne ze sítě.
Comment[da]=Datamotor der henter diverse online dagens billede.
Comment[de]=Daten-Treiber zum Holen verschiedener Bilder des Tages.
Comment[el]=Μηχανή δεδομένων για ανάκτηση διαφόρων διαδικτυακών φωτογραφιών της ημέρας.
Comment[en_GB]=Data Engine for getting various online Pictures of The Day.
Comment[es]=Motor de datos para obtener diversas imágenes del día de la red.
Comment[et]=Andmete mootor internetis leiduvate päevapiltide hankimiseks.
Comment[fi]=Tietomoottori erilaisten päivän kuvien noutamiseksi verkosta
Comment[fr]=Moteur de données permettant l'accès à divers sites d'images du jour.
Comment[gl]=Motor de datos para obter varias Imaxes do día en liña.
Comment[hr]=Podatkovni mehanizam za dohvaćanje raznih Slika dana na Internetu
Comment[hu]=Adatmotor különböző online A nap képe szolgáltatásokhoz.
Comment[is]=Gagnavél til að ná í ýmsar 'Myndir dagsins' á netinu.
Comment[it]=Motore dati per ottenere numerose immagini del giorno dalla rete.
Comment[ja]=
Comment[kk]=Түрлі онлайн Күнделікті суреттерді қабылдайтын тетігі
Comment[km]= 
Comment[ko]= .
Comment[lv]=Datu dzinējs, kas ielādē dažādus dienas attēlus.
Comment[mr]=िि ि ि ि ि
Comment[nb]=Datamotor for å hente forskjellige Dagens Bilder fra nettverket.
Comment[nds]=Datenkarn för't Halen vun verscheden Biller för Vundaag ut't Internet.
Comment[nl]=Gegevensengine voor het verkrijgen van online afbeeldingen-van-de-dag.
Comment[nn]=Datamotor for henting av dagens bilete
Comment[pl]=Silnik danych do pobierania różnych "obrazów dnia".
Comment[pt]=Motor de dados para obter diversas Imagens do Dia a nível 'online'.
Comment[pt_BR]=Mecanismo de dados para obter várias imagens do dia online.
Comment[ro]=Motor de date pentru obținerea Imaginii zilei din diverse locuri.
Comment[ru]=Источник различных "изображений дня" из сети
Comment[sk]=Nástroj na získavanie rôznych online obrázkov dňa.
Comment[sl]=Podatkovni pogon za pridobivanje raznih slik dneva s spleta.
Comment[sr]=Датомотор за добављање разних слика дана на вези.
Comment[sr@ijekavian]=Датомотор за добављање разних слика дана на вези.
Comment[sr@ijekavianlatin]=Datomotor za dobavljanje raznih slika dana na vezi.
Comment[sr@latin]=Datomotor za dobavljanje raznih slika dana na vezi.
Comment[sv]=Datagränssnitt för att hämta diverse dagens bilder från nätet.
Comment[tr]=Çeşitli çevrim içi Günün Resimleri için veri motoru.
Comment[uk]=Рушій даних для отримання різноманітних мережевих «Зображень дня»
Comment[wa]=Éndjin di dnêyes pos awè sacwantès Imådjes do djoû so fyis.
Comment[x-test]=xxData Engine for getting various online Pictures of The Day.xx
Comment[zh_CN]=线
Comment[zh_TW]=
X-KDE-ServiceTypes=Plasma/DataEngine
Type=Service
Icon=image-jpeg2000
X-KDE-Library=plasma_engine_potd
X-KDE-PluginInfo-Author=
X-KDE-PluginInfo-Email=
X-KDE-PluginInfo-Name=potd
X-KDE-PluginInfo-Version=
X-KDE-PluginInfo-Website=
X-KDE-PluginInfo-Category=

View file

@ -1,55 +0,0 @@
[Desktop Entry]
Type=ServiceType
X-KDE-ServiceType=PlasmaPoTD/Plugin
Comment=Plugin for Plasma PoTD Engine
Comment[ar]=ملحق لمحرك PoTD
Comment[ast]=Complementu pal motor d'imaxe del día de Plasma
Comment[bs]=Dodaci za plazma PoTD motor
Comment[ca]=Connector per al motor PoTD del plasma
Comment[ca@valencia]=Connector per al motor PoTD del plasma
Comment[cs]=Modul pro Plasma PoTD engine
Comment[da]=Plugin til Plasmas dagens billede-motor.
Comment[de]=Modul für den Plasma-Datentreiber Bilder des Tages
Comment[el]=Πρόσθετο της μηχανής Plasma PoTD
Comment[en_GB]=Plugin for Plasma PoTD Engine
Comment[es]=Complemento para el motor de imagen del día de Plasma
Comment[et]=Plasma päevapildi mootori plugin
Comment[fi]=Liitännäinen Plasman Päivän kuva -moottorille
Comment[fr]=Module externe Plasma pour le moteur « PoTD »
Comment[ga]=Breiseán le haghaidh inneall PoTD Plasma
Comment[gl]=Extensión para o motor PoTD de Plasma
Comment[hr]=Priključak za Plasmin mehanizam PoTD
Comment[hu]=Bővítmény a Plazma PoTD-motorhoz
Comment[is]=Íforrit fyrir PoTD plasmavél
Comment[it]=Estensione per il motore PoTD di Plasma
Comment[ja]=Plasma PoTD ()
Comment[kk]=Plasma PoTD (Күнделікті сурет) тетігінің плагині
Comment[km]= PoTD
Comment[ko]=Plasma
Comment[lv]=Spraudnis Plasma PoTD dzinējam
Comment[mr]= िि
Comment[nb]=Programtillegg for Plasma-motor Dagens Bilde
Comment[nds]=Moduul för Plasma sien BifV-Karn
Comment[nl]=Plug-in voor Plasma-PoTD-engine
Comment[nn]=Programtillegg for Plasma PoTD-motoren
Comment[pa]= PoTD
Comment[pl]=Wtyczka silnika PoTD Plazmy
Comment[pt]='Plugin' do Motor da Imagem do Dia do Plasma
Comment[pt_BR]=Plugin para o mecanismo PoTD do Plasma
Comment[ro]=Modul pentru motorul de imagine a zilei Plasma
Comment[ru]=Поддержка картинки дня для Plasma
Comment[sk]=Modul pre Plasma PoTD nástroj
Comment[sl]=Vstavek za pogon Slika dneva za Plasmo
Comment[sr]=Прикључак за Плазминог мотор слика дана
Comment[sr@ijekavian]=Прикључак за Плазминог мотор слика дана
Comment[sr@ijekavianlatin]=Priključak za Plasminog motor slika dana
Comment[sr@latin]=Priključak za Plasminog motor slika dana
Comment[sv]=Insticksprogram för Plasma gränssnitt till dagens bild
Comment[tr]=Plasma PoTD Motoru için Eklenti
Comment[uk]=Додаток для рушія Плазми PoTD
Comment[x-test]=xxPlugin for Plasma PoTD Enginexx
Comment[zh_CN]=Plasma
Comment[zh_TW]=Plasma PoTD
[PropertyDef::X-KDE-PlasmaPoTDProvider-Identifier]
Type=QString

View file

@ -1,187 +0,0 @@
/*
* Copyright (C) 2007 Tobias Koenig <tokoe@kde.org>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "potd.h"
#include <QtCore/qdatetime.h>
#include <QtCore/QFile>
#include <QtCore/QFileInfo>
#include <QtCore/QTimer>
#include <QtCore/QThreadPool>
#include <KDebug>
#include <KServiceTypeTrader>
#include <Plasma/DataContainer>
#include "cachedprovider.h"
#include "kstandarddirs.h"
PotdEngine::PotdEngine( QObject* parent, const QVariantList& args )
: Plasma::DataEngine( parent, args )
{
// set polling to every 5 minutes
setMinimumPollingInterval(5 * 60 * 1000);
m_checkDatesTimer = new QTimer( this );//change picture after 24 hours
connect( m_checkDatesTimer, SIGNAL(timeout()), this, SLOT(checkDayChanged()) );
//FIXME: would be nice to stop and start this timer ONLY as needed, e.g. only when there are
// time insensitive sources to serve; still, this is better than how i found it, checking
// every 2 seconds (!)
m_checkDatesTimer->setInterval( 10 * 60 * 1000 ); // check every 10 minutes
m_checkDatesTimer->start();
}
PotdEngine::~PotdEngine()
{
}
void PotdEngine::init()
{
KService::List services = KServiceTypeTrader::self()->query(QLatin1String( "PlasmaPoTD/Plugin" ));
Q_FOREACH ( const KService::Ptr &service, services ) {
QString provider = service->property(QLatin1String( "X-KDE-PlasmaPoTDProvider-Identifier" ), QVariant::String).toString();
mFactories.insert(provider, service);
setData( QLatin1String( "Providers" ), provider, service->name() );
}
}
bool PotdEngine::updateSourceEvent( const QString &identifier )
{
return updateSource( identifier, false );
}
bool PotdEngine::updateSource( const QString &identifier, bool loadCachedAlways )
{
// check whether it is cached already...
if ( CachedProvider::isCached( identifier, loadCachedAlways ) ) {
QVariantList args;
args << QLatin1String( "String" ) << identifier;
CachedProvider *provider = new CachedProvider( identifier, this );
connect( provider, SIGNAL(finished(PotdProvider*)), this, SLOT(finished(PotdProvider*)) );
connect( provider, SIGNAL(error(PotdProvider*)), this, SLOT(error(PotdProvider*)) );
m_canDiscardCache = loadCachedAlways;
if (!loadCachedAlways) {
return true;
}
}
const QStringList parts = identifier.split( QLatin1Char( ':' ), QString::SkipEmptyParts );
const QString providerName = parts[ 0 ];
if ( !mFactories.contains( providerName ) ) {
kDebug() << "invalid provider: " << parts[ 0 ];
return false;
}
QVariantList args;
args << providerName;
if ( parts.count() > 1 ) {
const QDate date = QDate::fromString( parts[ 1 ], Qt::ISODate );
if ( !date.isValid() ) {
kDebug() << "invalid date:" << parts[1];
return false;
}
args << date;
}
PotdProvider *provider = qobject_cast<PotdProvider*>( mFactories[ providerName ]->createInstance<QObject>( this, args ) );
if (provider) {
connect( provider, SIGNAL(finished(PotdProvider*)), this, SLOT(finished(PotdProvider*)) );
connect( provider, SIGNAL(error(PotdProvider*)), this, SLOT(error(PotdProvider*)) );
return true;
}
return false;
}
bool PotdEngine::sourceRequestEvent( const QString &identifier )
{
if ( updateSource( identifier, true ) ) {
setData( identifier, "Image", QImage() );
return true;
}
return false;
}
void PotdEngine::finished( PotdProvider *provider )
{
if ( m_canDiscardCache && qobject_cast<CachedProvider *>( provider ) ) {
Plasma::DataContainer *source = containerForSource( provider->identifier() );
if ( source && !source->data().value( "Image" ).value<QImage>().isNull() ) {
provider->deleteLater();
return;
}
}
QImage img(provider->image());
// store in cache if it's not the response of a CachedProvider
if ( qobject_cast<CachedProvider*>( provider ) == 0 && !img.isNull() ) {
SaveImageThread *thread = new SaveImageThread( provider->identifier(), img );
connect(thread, SIGNAL(done(QString,QString,QImage)), this, SLOT(cachingFinished(QString,QString,QImage)));
QThreadPool::globalInstance()->start(thread);
} else {
setData( provider->identifier(), "Image", img );
setData( provider->identifier(), "Url", CachedProvider::identifierToPath( provider->identifier()) );
}
provider->deleteLater();
}
void PotdEngine::cachingFinished( const QString &source, const QString &path, const QImage &img )
{
setData( source, "Image", img );
setData( source, "Url", path );
}
void PotdEngine::error( PotdProvider *provider )
{
provider->disconnect(this);
provider->deleteLater();
}
void PotdEngine::checkDayChanged()
{
SourceDict dict = containerDict();
QHashIterator<QString, Plasma::DataContainer*> it( dict );
while ( it.hasNext() ) {
it.next();
if ( it.key() == "Providers" ) {
continue;
}
if ( !it.key().contains(':') ) {
const QString path = CachedProvider::identifierToPath( it.key() );
if ( !QFile::exists(path) ) {
updateSourceEvent( it.key() );
} else {
QFileInfo info( path );
if ( info.lastModified().daysTo( QDateTime::currentDateTime() ) > 1 ) {
updateSourceEvent( it.key() );
}
}
}
}
}
#include "moc_potd.cpp"

View file

@ -1,69 +0,0 @@
/*
* Copyright (C) 2007 Tobias Koenig <tokoe@kde.org>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef POTD_DATAENGINE_H
#define POTD_DATAENGINE_H
#include "plasma/dataengine.h"
class PotdProvider;
#include <QTimer>
/**
* This class provides the Pictures of The Day from various online websites.
*
* The query keys have the following structure:
* <potd_identifier>:<date>
* e.g.
* apod:2007-07-19
*
*/
class PotdEngine : public Plasma::DataEngine
{
Q_OBJECT
public:
PotdEngine( QObject* parent, const QVariantList& args );
~PotdEngine();
protected:
void init();
bool sourceRequestEvent( const QString &identifier );
protected Q_SLOTS:
bool updateSourceEvent( const QString &identifier );
private Q_SLOTS:
void finished( PotdProvider* );
void error( PotdProvider* );
void checkDayChanged();
void cachingFinished( const QString &source, const QString &path, const QImage &img );
private:
bool updateSource( const QString &identifier, bool loadCachedAlways );
QMap<QString, KService::Ptr> mFactories;
QTimer *m_checkDatesTimer;
bool m_canDiscardCache;
};
K_EXPORT_PLASMA_DATAENGINE(potd, PotdEngine)
#endif

View file

@ -1,73 +0,0 @@
/*
* Copyright (C) 2007 Tobias Koenig <tokoe@kde.org>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "potdprovider.h"
class PotdProvider::Private
{
public:
QString name;
QDate date;
};
PotdProvider::PotdProvider( QObject *parent, const QVariantList &args )
: QObject( parent ),
d(new Private)
{
if ( args.count() > 0 ) {
d->name = args[ 0 ].toString();
if ( args.count() > 1 && args[ 1 ].canConvert( QVariant::Date ) ) {
d->date = args[ 1 ].toDate();
}
} else {
d->name = "Unknown";
}
}
PotdProvider::~PotdProvider()
{
}
QString PotdProvider::name() const
{
return d->name;
}
QDate PotdProvider::date() const
{
return d->date.isNull() ? QDate::currentDate() : d->date;
}
bool PotdProvider::isFixedDate() const
{
return !d->date.isNull();
}
QString PotdProvider::identifier() const
{
if (isFixedDate()) {
return QString( QLatin1String( "%1:%2" ) ).arg( d->name, d->date.toString( Qt::ISODate ));
}
return d->name;
}
#include "moc_potdprovider.cpp"

View file

@ -1,105 +0,0 @@
/*
* Copyright (C) 2007 Tobias Koenig <tokoe@kde.org>
*
* 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef POTDPROVIDER_H
#define POTDPROVIDER_H
#include <QtCore/QObject>
#include <QtCore/qdatetime.h>
#include <kpluginfactory.h>
#include "plasma_potd_export.h"
#include <QImage>
#define POTDPROVIDER_EXPORT_PLUGIN( classname, componentName, catalogName ) \
K_PLUGIN_FACTORY( classname ## Factory, registerPlugin< classname >(); ) \
K_EXPORT_PLUGIN( classname ## Factory( componentName, catalogName ) )
/**
* This class is an interface for PoTD providers.
*/
class PLASMA_POTD_EXPORT PotdProvider : public QObject
{
Q_OBJECT
public:
/**
* Creates a new PoTD provider.
*
* @param parent The parent object.
*/
PotdProvider( QObject *parent, const QVariantList &args = QVariantList() );
/**
* Destroys the PoTD provider.
*/
virtual ~PotdProvider();
/**
* Returns the requested image.
*
* Note: This method returns only a valid image after the
* finished() signal has been emitted.
*/
virtual QImage image() const = 0;
/**
* Returns the identifier of the PoTD request (name + date).
*/
virtual QString identifier() const;
/**
* @return the name of this provider (equiv to X-KDE-PlasmaPoTDProvider-Identifier)
*/
QString name() const;
/**
* @reutrn the date to load for this item, if any
*/
QDate date() const;
/**
* @return if the date is fixed, or if it should always be "today"
*/
bool isFixedDate() const;
Q_SIGNALS:
/**
* This signal is emitted whenever a request has been finished
* successfully.
*
* @param provider The provider which emitted the signal.
*/
void finished( PotdProvider *provider );
/**
* This signal is emitted whenever an error has occurred.
*
* @param provider The provider which emitted the signal.
*/
void error( PotdProvider *provider );
private:
class Private;
Private * const d;
};
#endif

View file

@ -1,3 +1,2 @@
add_subdirectory(potd)
add_subdirectory(virus)
add_subdirectory(pattern)

View file

@ -1,12 +0,0 @@
project(plasma-wallpaper-potd)
set(potd_SRCS
potd.cpp
config.ui
)
kde4_add_plugin(plasma_wallpaper_potd ${potd_SRCS})
target_link_libraries(plasma_wallpaper_potd KDE4::plasma KDE4::kdeui KDE4::kio)
install(TARGETS plasma_wallpaper_potd DESTINATION ${KDE4_PLUGIN_INSTALL_DIR})
install(FILES plasma-wallpaper-potd.desktop DESTINATION ${KDE4_SERVICES_INSTALL_DIR})

View file

@ -1,5 +0,0 @@
#! /usr/bin/env bash
$EXTRACTRC *.ui >> rc.cpp
$XGETTEXT *.cpp -o $podir/plasma_wallpaper_potd.pot
rm -f rc.cpp

View file

@ -1,76 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Configuration</class>
<widget class="QWidget" name="Configuration">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>390</width>
<height>228</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="providerLabel">
<property name="text">
<string>Source:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>providers</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="providers">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="positioningLabel">
<property name="text">
<string>P&amp;ositioning</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>resizeMethod</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="resizeMethod">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>324</width>
<height>186</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<connections/>
</ui>

View file

@ -1,105 +0,0 @@
[Desktop Entry]
Name=Picture of the Day
Name[ar]=صورة اليوم
Name[ast]=Imaxe del día
Name[bs]=Slika dana
Name[ca]=Imatge del dia
Name[ca@valencia]=Imatge del dia
Name[cs]=Obrázek dne
Name[da]=Dagens billede
Name[de]=Bild des Tages
Name[el]=Φωτογραφία της ημέρας
Name[en_GB]=Picture of the Day
Name[es]=Imagen del día
Name[et]=Päevapilt
Name[fi]=Päivän kuva
Name[fr]=Image du jour
Name[ga]=Grianghraf an Lae
Name[gl]=Imaxe do día
Name[hr]=Slika dana
Name[hu]=A nap képe
Name[is]=Myndir dagsins
Name[it]=Immagine del giorno
Name[ja]=
Name[kk]=Тәулік суреті
Name[km]=
Name[ko]=
Name[lt]=Dienos paveiksliukas
Name[lv]=Dienas attēls
Name[mr]=ि ि
Name[nb]=Dagens bilde
Name[nds]=Bild för Vundaag
Name[nl]=Afbeelding van de dag
Name[nn]=Dagens bilete
Name[pa]=
Name[pl]=Obraz dnia
Name[pt]=Imagem do Dia
Name[pt_BR]=Imagem do dia
Name[ro]=Imaginea zilei
Name[ru]=Изображение дня
Name[sk]=Obrázok dňa
Name[sl]=Slika dneva
Name[sr]=слика дана
Name[sr@ijekavian]=слика дана
Name[sr@ijekavianlatin]=slika dana
Name[sr@latin]=slika dana
Name[sv]=Dagens bild
Name[tr]=Günün Resmi
Name[uk]=Картинка дня
Name[wa]=Imådje do djoû
Name[x-test]=xxPicture of the Dayxx
Name[zh_CN]=
Name[zh_TW]=
Comment=A new picture from the Internet each day
Comment[ar]=صورة من السابكة كل يوم
Comment[bs]=Nova slika sa Interneta svaki dan
Comment[ca]=Una imatge nova des d'Internet cada dia
Comment[ca@valencia]=Una imatge nova des d'Internet cada dia
Comment[cs]=Nový obrázek z internetu denně
Comment[da]=Et nyt billede fra internettet hver dag
Comment[de]=Täglich ein Bild aus dem Internet anzeigen
Comment[el]=Κάθε μέρα μια νέα εικόνα από το διαδίκτυο
Comment[en_GB]=A new picture from the Internet each day
Comment[es]=Una nueva imagen desde Internet cada día
Comment[et]=Iga päev uus pilt internetist
Comment[fi]=Joka päivä uusi kuva Internetistä
Comment[fr]=Une nouvelle image chaque jour provenant d'Internet
Comment[gl]=Mostra imaxes de internet cada día.
Comment[hu]=Minden nap új kép az internetről
Comment[it]=Una nuova immagine ogni giorno da Internet.
Comment[kk]=Күнде Интернеттен жаңа сурет
Comment[ko]=
Comment[nb]=Et nytt bilde fra Internett hver dag
Comment[nds]=Elk Dag en nieg Bild ut dat Internet halen
Comment[nl]=Elke dag een nieuw plaatje uit het internet
Comment[pl]=Każdego dnia nowe zdjęcie z internetu
Comment[pt]=Uma nova imagem diária da Internet
Comment[pt_BR]=Uma nova imagem diária da Internet
Comment[ro]=O nouă imagine din Internet în fiecare zi
Comment[ru]=Новое изображение из Интернета каждый день
Comment[sk]=Nový obrázok z Internetu každý deň
Comment[sl]=Nova slika z interneta vsak dan
Comment[sr]=Сваки дан нова слика са Интернета
Comment[sr@ijekavian]=Сваки дан нова слика са Интернета
Comment[sr@ijekavianlatin]=Svaki dan nova slika sa Interneta
Comment[sr@latin]=Svaki dan nova slika sa Interneta
Comment[sv]=En ny bild från Internet varje dag
Comment[tr]=Her gün İnternet'ten yeni bir resim göster
Comment[uk]=Нове зображення з інтернету щодня
Comment[x-test]=xxA new picture from the Internet each dayxx
Comment[zh_CN]=
Comment[zh_TW]=
Type=Service
Icon=office-calendar
ServiceTypes=Plasma/Wallpaper
X-KDE-Library=plasma_wallpaper_potd
X-KDE-PluginInfo-Author=Aaron Seigo
X-KDE-PluginInfo-Email=aseigo@kde.org
X-KDE-PluginInfo-Name=org.kde.potd
X-KDE-PluginInfo-Version=0.1
X-KDE-PluginInfo-Website=
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true

View file

@ -1,237 +0,0 @@
/*
* Copyright 2011 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "potd.h"
#include <QPainter>
#include <QThreadPool>
#include <KDebug>
#include <KAction>
#include <KFileDialog>
#include <KStandardAction>
#include <KImageIO>
static const QString DEFAULT_PROVIDER("apod");
static const int DEFAULT_RESIZE_METHOD = Plasma::Wallpaper::ScaledResize;
SaveRunnable::SaveRunnable(Plasma::DataEngine *dataEngine, const QString &provider, const QString &path)
: m_dataEngine(dataEngine),
m_path(path)
{
dataEngine->connectSource(provider, this);
kDebug() << "saving to" << m_path;
setAutoDelete(true);
}
void SaveRunnable::run()
{
kDebug() << "saving?";
if (m_image.isNull() || m_path.isEmpty()) {
return;
}
kDebug() << "saving!";
m_image.save(m_path);
}
void SaveRunnable::dataUpdated(const QString &source, const Plasma::DataEngine::Data &data)
{
if (!m_dataEngine) {
deleteLater();
return;
}
m_image = data["Image"].value<QImage>();
m_dataEngine.data()->disconnectSource(source, this);
QThreadPool::globalInstance()->start(this);
}
PoTD::PoTD(QObject *parent, const QVariantList &args)
: Plasma::Wallpaper(parent, args)
{
m_resizeMethod = DEFAULT_RESIZE_METHOD;
m_configResizeMethod = -1;
connect(this, SIGNAL(renderCompleted(QImage)), this, SLOT(wallpaperRendered(QImage)));
dataEngine(QLatin1String("potd"))->connectSource(QLatin1String("Providers"), this);
setUsingRenderingCache(false);
QAction *saveFile = KStandardAction::save(this, SLOT(getSaveFileLocation()), this);
saveFile->setText(i18n("Save wallpaper image..."));
saveFile->setShortcut(QKeySequence());
setContextualActions(QList<QAction *>() << saveFile);
}
void PoTD::init(const KConfigGroup &config)
{
QString provider = config.readEntry(QLatin1String("provider"), DEFAULT_PROVIDER);
int resizeMethod = config.readEntry("wallpaperposition", DEFAULT_RESIZE_METHOD);
if (provider.isEmpty() || (!m_providers.isEmpty() && !m_providers.contains(provider))) {
provider = DEFAULT_PROVIDER;
}
if (provider != m_provider || m_resizeMethod != resizeMethod) {
if (!m_provider.isEmpty()) {
dataEngine(QLatin1String("potd"))->disconnectSource(m_provider, this);
}
m_provider = provider;
m_resizeMethod = resizeMethod;
if (!isPreviewing()) {
dataEngine(QLatin1String("potd"))->connectSource(m_provider, this);
}
}
}
void PoTD::wallpaperRendered(const QImage &image)
{
m_image = image;
emit update(boundingRect());
}
void PoTD::dataUpdated(const QString &source, const Plasma::DataEngine::Data &data)
{
if (source == QLatin1String("Providers")) {
m_providers = data;
if (!m_provider.isEmpty() && !m_providers.contains(m_provider)) {
Plasma::DataEngine *engine = dataEngine(QLatin1String("potd"));
engine->disconnectSource(m_provider, this);
m_provider = DEFAULT_PROVIDER;
engine->connectSource(m_provider, this);
}
} else if (source == m_provider) {
QImage image = data["Image"].value<QImage>();
render(image, boundingRect().size().toSize(), (ResizeMethod)m_resizeMethod);
} else {
dataEngine(QLatin1String("potd"))->disconnectSource(source, this);
}
}
void PoTD::getSaveFileLocation()
{
if (m_provider.isNull()) {
return;
}
KFileDialog *fd = new KFileDialog(
KUrl("kfiledialog:///potdwallpaper"),
KImageIO::pattern(KImageIO::Writing),
0
);
fd->setOperationMode(KFileDialog::Saving);
fd->setMode(KFile::LocalOnly);
fd->setAttribute(Qt::WA_DeleteOnClose, true);
connect(fd, SIGNAL(okClicked()), this, SLOT(saveFile()));
fd->show();
}
void PoTD::saveFile()
{
KFileDialog *fd = qobject_cast<KFileDialog *>(sender());
const QString &path = fd->selectedFile();
if (path.isEmpty() || m_provider.isEmpty()) {
return;
}
new SaveRunnable(dataEngine(QLatin1String("potd")), m_provider, path);
}
void PoTD::paint(QPainter *painter, const QRectF& exposedRect)
{
if (m_image.isNull()) {
painter->fillRect(exposedRect, QBrush(Qt::black));
const QString provider = m_providers.isEmpty() || m_provider.isEmpty() ? QString()
: m_providers.value(m_provider).toString();
const QString text = provider.isEmpty() ? i18n("Loading the picture of the day...")
: i18n("Loading the picture of the day from %1...", provider);
QRect textRect = painter->fontMetrics().boundingRect(text);
textRect.moveCenter(boundingRect().center().toPoint());
painter->setPen(Qt::white);
painter->drawText(textRect.topLeft(), text);
} else {
if (m_image.size() != boundingRect().size().toSize()) {
Plasma::DataEngine *engine = dataEngine(QLatin1String("potd"));
// refresh the data which will trigger a re-render
engine->disconnectSource(m_provider, this);
engine->connectSource(m_provider, this);
}
painter->drawImage(exposedRect, m_image, exposedRect);
}
}
QWidget* PoTD::createConfigurationInterface(QWidget* parent)
{
QWidget *widget = new QWidget(parent);
m_ui.setupUi(widget);
m_configProvider.clear();
m_configResizeMethod = -1;
Plasma::DataEngine::DataIterator it(m_providers);
while (it.hasNext()) {
it.next();
m_ui.providers->addItem(it.value().toString(), it.key());
if (m_provider == it.key()) {
m_ui.providers->setCurrentIndex(m_ui.providers->count() - 1);
}
}
connect(m_ui.providers, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsModified()));
connect(this, SIGNAL(settingsChanged(bool)), parent, SLOT(settingsChanged(bool)));
m_ui.resizeMethod->addItem(i18n("Scaled & Cropped"), ScaledAndCroppedResize);
m_ui.resizeMethod->addItem(i18n("Scaled"), ScaledResize);
m_ui.resizeMethod->addItem(i18n("Scaled, keep proportions"), MaxpectResize);
m_ui.resizeMethod->addItem(i18n("Centered"), CenteredResize);
m_ui.resizeMethod->addItem(i18n("Tiled"), TiledResize);
m_ui.resizeMethod->addItem(i18n("Center Tiled"), CenterTiledResize);
for (int i = 0; i < m_ui.resizeMethod->count(); ++i) {
if (m_resizeMethod == m_ui.resizeMethod->itemData(i).value<int>()) {
m_ui.resizeMethod->setCurrentIndex(i);
break;
}
}
connect(m_ui.resizeMethod, SIGNAL(currentIndexChanged(int)), this, SLOT(settingsModified()));
return widget;
}
void PoTD::save(KConfigGroup &config)
{
if (m_configProvider.isEmpty()) {
config.writeEntry("provider", m_provider);
} else {
config.writeEntry("provider", m_configProvider);
m_configProvider.clear();
}
if (m_configResizeMethod == -1) {
config.writeEntry("wallpaperposition", m_resizeMethod);
} else {
config.writeEntry("wallpaperposition", m_configResizeMethod);
m_configResizeMethod = -1;
}
}
void PoTD::settingsModified()
{
m_configProvider = m_ui.providers->itemData(m_ui.providers->currentIndex()).toString();
m_configResizeMethod = m_ui.resizeMethod->itemData(m_ui.resizeMethod->currentIndex()).value<int>();
emit settingsChanged(true);
}
#include "moc_potd.cpp"

View file

@ -1,85 +0,0 @@
/*
* Copyright 2011 Aaron Seigo <aseigo@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2, 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
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef COLOR_HEADER
#define COLOR_HEADER
#include <QRunnable>
#include <QtCore/qsharedpointer.h>
#include <Plasma/Wallpaper>
#include <Plasma/DataEngine>
#include "ui_config.h"
class SaveRunnable : public QObject, QRunnable
{
Q_OBJECT
public:
SaveRunnable(Plasma::DataEngine *dataEngine, const QString &provider, const QString &path);
void run();
public Q_SLOTS:
void dataUpdated(const QString &source, const Plasma::DataEngine::Data &data);
private:
QWeakPointer<Plasma::DataEngine> m_dataEngine;
QImage m_image;
QString m_path;
};
class PoTD : public Plasma::Wallpaper
{
Q_OBJECT
public:
PoTD(QObject* parent, const QVariantList& args);
void save(KConfigGroup &config);
void paint(QPainter* painter, const QRectF& exposedRect);
QWidget *createConfigurationInterface(QWidget* parent);
public Q_SLOTS:
void wallpaperRendered(const QImage &image);
void dataUpdated(const QString &source, const Plasma::DataEngine::Data &data);
Q_SIGNALS:
void settingsChanged(bool modified);
protected:
virtual void init(const KConfigGroup &config);
protected slots:
void settingsModified();
void getSaveFileLocation();
void saveFile();
private:
Ui::Configuration m_ui;
Plasma::DataEngine::Data m_providers;
QString m_provider;
QString m_configProvider;
int m_resizeMethod;
int m_configResizeMethod;
QImage m_image;
};
K_EXPORT_PLASMA_WALLPAPER(potd, PoTD)
#endif