diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d8a55547..60c743f3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,61 +1,61 @@ project(kdeplasma-addons) set(PROJECT_VERSION "5.8.90") set(PROJECT_VERSION_MAJOR 5) cmake_minimum_required(VERSION 2.8.12) ################# Disallow in-source build ################# if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") message(FATAL_ERROR "plasma requires an out of source build. Please create a separate build directory and run 'cmake path_to_plasma [options]' there.") endif() include(FeatureSummary) find_package(ECM 1.0.0 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) set(REQUIRED_QT_VERSION 5.3.0) set(KF5_MIN_VERSION 5.8.0) find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core Gui DBus Quick Qml Widgets X11Extras) find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS - Activities Config ConfigWidgets CoreAddons I18n KIO KCMUtils Plasma Runner Service UnitConversion KDELibs4Support NewStuff Kross WebKit) + Activities Config ConfigWidgets CoreAddons I18n KIO KCMUtils Plasma Runner Service UnitConversion KDELibs4Support NewStuff Kross) find_package(LibTaskManager CONFIG REQUIRED) find_package(X11) set_package_properties(X11 PROPERTIES DESCRIPTION "X11 libraries" URL "http://www.x.org" TYPE REQUIRED PURPOSE "Required for building the X11 based workspace" ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_definitions(-DQT_NO_URL_CAST_FROM_STRING) ######################################################################### ################# list the subdirectories ################# #add_subdirectory(src) #add_subdirectory( desktoptheme ) add_subdirectory(libs) add_subdirectory(applets) add_subdirectory(dataengines) add_subdirectory(runners) add_subdirectory(wallpapers) add_subdirectory(windowswitchers) add_subdirectory(desktopswitchers) configure_file(config-kdeplasma-addons.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kdeplasma-addons.h) configure_file(config-X11.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-X11.h) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/dataengines/potd/CMakeLists.txt b/dataengines/potd/CMakeLists.txt index b13db8765..e8163e5c8 100644 --- a/dataengines/potd/CMakeLists.txt +++ b/dataengines/potd/CMakeLists.txt @@ -1,98 +1,98 @@ set(potd_engine_SRCS cachedprovider.cpp potd.cpp ) add_library(plasma_engine_potd MODULE ${potd_engine_SRCS} ) target_link_libraries(plasma_engine_potd plasmapotdprovidercore KF5::Plasma KF5::KIOCore ) kcoreaddons_desktop_to_json(plasma_engine_potd plasma-dataengine-potd.desktop SERVICE_TYPES plasma-dataengine.desktop) install(TARGETS plasma_engine_potd DESTINATION ${PLUGIN_INSTALL_DIR}/plasma/dataengine ) install(FILES plasma-dataengine-potd.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) ########### plugin core library ############ set(potd_provider_core_SRCS potdprovider.cpp ${CMAKE_CURRENT_BINARY_DIR}/plasma_potd_export.h ) add_library( plasmapotdprovidercore SHARED ${potd_provider_core_SRCS} ) target_link_libraries( plasmapotdprovidercore Qt5::Gui KF5::CoreAddons ) set_target_properties( plasmapotdprovidercore PROPERTIES VERSION 1.0.0 SOVERSION 1 ) generate_export_header(plasmapotdprovidercore BASE_NAME PLASMA_POTD EXPORT_FILE_NAME plasma_potd_export.h) install( TARGETS plasmapotdprovidercore ${INSTALL_TARGETS_DEFAULT_ARGS} ) ########### plugins ############### set( potd_flickr_provider_SRCS flickrprovider.cpp ) add_library( plasma_potd_flickrprovider MODULE ${potd_flickr_provider_SRCS} ) target_link_libraries( plasma_potd_flickrprovider plasmapotdprovidercore KF5::KIOCore KF5::CoreAddons) kcoreaddons_desktop_to_json(plasma_potd_flickrprovider flickrprovider.desktop SERVICE_TYPES ${CMAKE_CURRENT_SOURCE_DIR}/plasma_potdprovider.desktop) install( TARGETS plasma_potd_flickrprovider DESTINATION ${PLUGIN_INSTALL_DIR}/potd ) set( potd_apod_provider_SRCS apodprovider.cpp ) add_library( plasma_potd_apodprovider MODULE ${potd_apod_provider_SRCS} ) target_link_libraries( plasma_potd_apodprovider plasmapotdprovidercore KF5::KIOCore) kcoreaddons_desktop_to_json(plasma_potd_apodprovider apodprovider.desktop SERVICE_TYPES ${CMAKE_CURRENT_SOURCE_DIR}/plasma_potdprovider.desktop) install( TARGETS plasma_potd_apodprovider DESTINATION ${PLUGIN_INSTALL_DIR}/potd ) set( potd_natgeo_provider_SRCS natgeoprovider.cpp ) add_library( plasma_potd_natgeoprovider MODULE ${potd_natgeo_provider_SRCS} ) -target_link_libraries( plasma_potd_natgeoprovider plasmapotdprovidercore KF5::KIOCore KF5::WebKit) +target_link_libraries( plasma_potd_natgeoprovider plasmapotdprovidercore KF5::KIOCore) kcoreaddons_desktop_to_json(plasma_potd_natgeoprovider natgeoprovider.desktop SERVICE_TYPES ${CMAKE_CURRENT_SOURCE_DIR}/plasma_potdprovider.desktop) install( TARGETS plasma_potd_natgeoprovider DESTINATION ${PLUGIN_INSTALL_DIR}/potd ) set( potd_epod_provider_SRCS epodprovider.cpp ) add_library( plasma_potd_epodprovider MODULE ${potd_epod_provider_SRCS} ) target_link_libraries( plasma_potd_epodprovider plasmapotdprovidercore KF5::KIOCore) kcoreaddons_desktop_to_json(plasma_potd_epodprovider epodprovider.desktop SERVICE_TYPES ${CMAKE_CURRENT_SOURCE_DIR}/plasma_potdprovider.desktop) install( TARGETS plasma_potd_epodprovider DESTINATION ${PLUGIN_INSTALL_DIR}/potd ) set( potd_noaa_provider_SRCS noaaprovider.cpp ) add_library( plasma_potd_noaaprovider MODULE ${potd_noaa_provider_SRCS} ) -target_link_libraries( plasma_potd_noaaprovider plasmapotdprovidercore KF5::KIOCore KF5::WebKit) +target_link_libraries( plasma_potd_noaaprovider plasmapotdprovidercore KF5::KIOCore) kcoreaddons_desktop_to_json(plasma_potd_noaaprovider noaaprovider.desktop SERVICE_TYPES ${CMAKE_CURRENT_SOURCE_DIR}/plasma_potdprovider.desktop) install( TARGETS plasma_potd_noaaprovider DESTINATION ${PLUGIN_INSTALL_DIR}/potd ) set( potd_wcpotd_provider_SRCS wcpotdprovider.cpp ) add_library( plasma_potd_wcpotdprovider MODULE ${potd_wcpotd_provider_SRCS} ) target_link_libraries( plasma_potd_wcpotdprovider plasmapotdprovidercore KF5::KIOCore ) kcoreaddons_desktop_to_json(plasma_potd_wcpotdprovider wcpotdprovider.desktop SERVICE_TYPES ${CMAKE_CURRENT_SOURCE_DIR}/plasma_potdprovider.desktop) install( TARGETS plasma_potd_wcpotdprovider DESTINATION ${PLUGIN_INSTALL_DIR}/potd ) diff --git a/dataengines/potd/natgeoprovider.cpp b/dataengines/potd/natgeoprovider.cpp index 090cad219..d15644038 100644 --- a/dataengines/potd/natgeoprovider.cpp +++ b/dataengines/potd/natgeoprovider.cpp @@ -1,114 +1,119 @@ /* * Copyright 2007 Tobias Koenig * Copyright 2008 Anne-Marie Mahfouf * Copyright 2013 Aaron Seigo * * 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 "natgeoprovider.h" #include #include +#include #include #include -#include -#include -#include -#include - class NatGeoProvider::Private { public: Private( NatGeoProvider *parent ) - : mParent( parent ), - mPage( new KWebPage( parent, KWebPage::KIOIntegration ) ) + : mParent( parent ) { } - void pageRequestFinished( bool ok ); + void pageRequestFinished( KJob* ); void imageRequestFinished( KJob* ); NatGeoProvider *mParent; QImage mImage; - KWebPage *mPage; + + QXmlStreamReader mXmlReader; }; -void NatGeoProvider::Private::pageRequestFinished( bool ok ) +void NatGeoProvider::Private::pageRequestFinished( KJob* _job ) { - if ( !ok ) { + KIO::StoredTransferJob *job = static_cast( _job ); + if (job->error()) { emit mParent->error( mParent ); return; } - QWebElementCollection links = mPage->mainFrame()->findAllElements( QLatin1String( "meta" ) ); - if ( links.count() < 1 ) { - emit mParent->error( mParent ); - return; - } + const QString data = QString::fromUtf8( job->data() ); + + mXmlReader.clear(); + mXmlReader.addData(data); QString url; - for (int i = 0, e = links.count(); i < e; i++) { - if (links.at(i).attribute(QLatin1String("property")) == "og:image") { - url = links.at(i).attribute(QLatin1String("content")); - break; + while (!mXmlReader.atEnd()) { + mXmlReader.readNext(); + + if (mXmlReader.isStartElement() && mXmlReader.name() == QLatin1String( "meta" )) { + const auto attrs = mXmlReader.attributes(); + if (attrs.value(QLatin1String("property")).toString() == QLatin1String("og:image")) { + url = attrs.value(QLatin1String("content")).toString(); + break; + } } } + if (url.isEmpty()) { emit mParent->error( mParent ); return; } KIO::StoredTransferJob *imageJob = KIO::storedGet( QUrl(url), KIO::NoReload, KIO::HideProgressInfo ); - mParent->connect( imageJob, SIGNAL(finished(KJob*)), SLOT(imageRequestFinished(KJob*)) ); + mParent->connect( imageJob, &KIO::StoredTransferJob::finished, mParent, [this] (KJob *job) { + imageRequestFinished(job); + }); } void NatGeoProvider::Private::imageRequestFinished( KJob *_job ) { KIO::StoredTransferJob *job = static_cast( _job ); if ( job->error() ) { emit mParent->error( mParent ); return; } mImage = QImage::fromData( job->data() ); emit mParent->finished( mParent ); } NatGeoProvider::NatGeoProvider( QObject *parent, const QVariantList &args ) : PotdProvider( parent, args ), d( new Private( this ) ) { const QUrl url( QLatin1String( "https://www.nationalgeographic.com/photography/photo-of-the-day" ) ); - connect( d->mPage, SIGNAL(loadFinished(bool)), this, SLOT(pageRequestFinished(bool)) ); - d->mPage->mainFrame()->setUrl( url ); + KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo ); + connect( job, &KIO::StoredTransferJob::finished, this, [this] (KJob *job) { + d->pageRequestFinished(job); + }); } NatGeoProvider::~NatGeoProvider() { delete d; } QImage NatGeoProvider::image() const { return d->mImage; } K_PLUGIN_FACTORY_WITH_JSON(NatGeoProviderFactory, "natgeoprovider.json", registerPlugin();) #include "natgeoprovider.moc" -#include "moc_natgeoprovider.moc" diff --git a/dataengines/potd/natgeoprovider.h b/dataengines/potd/natgeoprovider.h index 4ce839b60..dd32dde90 100644 --- a/dataengines/potd/natgeoprovider.h +++ b/dataengines/potd/natgeoprovider.h @@ -1,70 +1,67 @@ /* * Copyright 2007 Tobias Koenig * Copyright 2008 Anne-Marie Mahfouf * Copyright 2013 Aaron Seigo * * 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 NATGEOPROVIDER_H #define NATGEOPROVIDER_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 NatGeoProvider : 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. */ NatGeoProvider( QObject *parent, const QVariantList &args ); /** * Destroys the APOD provider. */ ~NatGeoProvider(); /** * 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( bool ) ) - Q_PRIVATE_SLOT( d, void imageRequestFinished( KJob* ) ) }; #endif diff --git a/dataengines/potd/noaaprovider.cpp b/dataengines/potd/noaaprovider.cpp index 3886695c3..cacd48509 100644 --- a/dataengines/potd/noaaprovider.cpp +++ b/dataengines/potd/noaaprovider.cpp @@ -1,113 +1,112 @@ /* * Copyright (C) 2007 Tobias Koenig * Copyright 2008 by Anne-Marie Mahfouf * * 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 "noaaprovider.h" #include #include +#include #include #include -#include -#include -#include class NOAAProvider::Private { public: Private( NOAAProvider *parent ) - : mParent( parent ), - mPage( new KWebPage( parent, KWebPage::KIOIntegration ) ) + : mParent( parent ) { } - void pageRequestFinished( bool ); + void pageRequestFinished( KJob* ); void imageRequestFinished( KJob* ); void parsePage(); NOAAProvider *mParent; QImage mImage; - KWebPage *mPage; }; -void NOAAProvider::Private::pageRequestFinished( bool ok ) +void NOAAProvider::Private::pageRequestFinished( KJob* _job ) { - if ( !ok ) { - emit mParent->error( mParent ); - return; - } - - QWebElementCollection links = mPage->mainFrame()->findAllElements( QLatin1String( "script" ) ); - if ( links.count() < 1 ) { + KIO::StoredTransferJob *job = static_cast( _job ); + if (job->error()) { emit mParent->error( mParent ); return; } + const QString data = QString::fromUtf8( job->data() ); + + // Using regular expression could be fragile in such case, but the HTML + // NOAA page itself is not a valid XML file and unfortunately it could + // not be parsed successfully till the content we want. And we do not want + // to use heavy weight QtWebkit. So we use QRegularExpression to capture + // the wanted url here. QString url; - for (int i = 0, e = links.count(); i < e; i++) { - const auto text = links.at(i).toPlainText(); - if (text.startsWith("_curPic = ")) { - url = "http://www.nnvl.noaa.gov/" + text.mid(10); - break; - } + QRegularExpression re("_curPic = (.*?)"); + auto result = re.match(data); + if (result.hasMatch()) { + url = QString("http://www.nnvl.noaa.gov/").append(result.captured(1)); } if (url.isEmpty()) { emit mParent->error( mParent ); return; } KIO::StoredTransferJob *imageJob = KIO::storedGet( QUrl(url), KIO::NoReload, KIO::HideProgressInfo ); - mParent->connect( imageJob, SIGNAL(finished(KJob*)), SLOT(imageRequestFinished(KJob*)) ); + mParent->connect( imageJob, &KIO::StoredTransferJob::finished, mParent, [this] (KJob* job) { + imageRequestFinished(job); + }); } void NOAAProvider::Private::imageRequestFinished( KJob *_job ) { KIO::StoredTransferJob *job = static_cast( _job ); if ( job->error() ) { emit mParent->error( mParent ); return; } mImage = QImage::fromData( job->data() ); emit mParent->finished( mParent ); } NOAAProvider::NOAAProvider( QObject *parent, const QVariantList &args ) : PotdProvider( parent, args ), d( new Private( this ) ) { QUrl url( QLatin1String( "http://www.nnvl.noaa.gov/imageoftheday.php" ) ); - connect( d->mPage, SIGNAL(loadFinished(bool)), this, SLOT(pageRequestFinished(bool)) ); - d->mPage->mainFrame()->setUrl( url ); + KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo ); + connect( job, &KIO::StoredTransferJob::finished, this, [this] (KJob *job) { + d->pageRequestFinished(job); + }); } NOAAProvider::~NOAAProvider() { delete d; } QImage NOAAProvider::image() const { return d->mImage; } K_PLUGIN_FACTORY_WITH_JSON(NOAAProviderFactory, "noaaprovider.json", registerPlugin();) -#include "moc_noaaprovider.cpp" #include "noaaprovider.moc" diff --git a/dataengines/potd/noaaprovider.h b/dataengines/potd/noaaprovider.h index 23e19b9cb..5e2e40719 100644 --- a/dataengines/potd/noaaprovider.h +++ b/dataengines/potd/noaaprovider.h @@ -1,66 +1,63 @@ /* * Copyright (C) 2007 Tobias Koenig * Copyright 2008 by Anne-Marie Mahfouf * Copyright 2016 Weng Xuetian * * 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 NOAAPROVIDER_H #define NOAAPROVIDER_H #include "potdprovider.h" /** * This class provides the image for NOAA Environmental Visualization Laboratory * Picture Of the Day * located at http://www.nnvl.noaa.gov/imageoftheday.php. */ class NOAAProvider : public PotdProvider { Q_OBJECT public: /** * Creates a new NOAA provider. * * @param date The date for which the image shall be fetched. * @param parent The parent object. */ NOAAProvider( QObject *parent, const QVariantList &args ); /** * Destroys the NOAA provider. */ ~NOAAProvider(); /** * 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( bool ) ) - Q_PRIVATE_SLOT( d, void imageRequestFinished( KJob* ) ) }; #endif