diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,9 @@ include(KDECompilerSettings NO_POLICY_SCOPE) include(ECMQtDeclareLoggingCategory) include(ECMInstallIcons) +include(KDEPackageAppTemplates) include(GenerateExportHeader) +include(CMakePackageConfigHelpers) find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core @@ -85,4 +87,6 @@ add_subdirectory(windowswitchers) add_subdirectory(desktopswitchers) +add_subdirectory(templates) + feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/dataengines/potd/CMakeLists.txt b/dataengines/potd/CMakeLists.txt --- a/dataengines/potd/CMakeLists.txt +++ b/dataengines/potd/CMakeLists.txt @@ -16,18 +16,60 @@ ########### plugin core library ############ +set(POTDPROVIDER_VERSION 1.0.0) +set(POTDPROVIDER_VERSION_MAJOR 1) set(potd_provider_core_SRCS potdprovider.cpp ${CMAKE_CURRENT_BINARY_DIR}/plasma_potd_export.h ) add_library( plasmapotdprovidercore SHARED ${potd_provider_core_SRCS} ) +add_library(Plasma::PotdProvider ALIAS plasmapotdprovidercore) +set_target_properties(plasmapotdprovidercore PROPERTIES + VERSION ${POTDPROVIDER_VERSION} + SOVERSION ${POTDPROVIDER_VERSION_MAJOR} + EXPORT_NAME PotdProvider +) target_link_libraries( plasmapotdprovidercore Qt5::Gui KF5::CoreAddons ) -set_target_properties( plasmapotdprovidercore PROPERTIES VERSION 1.0.0 SOVERSION 1 ) +target_include_directories(plasmapotdprovidercore + PUBLIC "$" + INTERFACE "$" +) generate_export_header(plasmapotdprovidercore BASE_NAME PLASMA_POTD EXPORT_FILE_NAME plasma_potd_export.h) -install( TARGETS plasmapotdprovidercore ${INSTALL_TARGETS_DEFAULT_ARGS} ) +install(TARGETS plasmapotdprovidercore EXPORT plasmapotdproviderTargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ) +install(FILES + potdprovider.h + ${CMAKE_CURRENT_BINARY_DIR}/plasma_potd_export.h + DESTINATION ${KDE_INSTALL_INCLUDEDIR}/plasma/potdprovider + COMPONENT Devel +) + +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/PlasmaPotdProviderConfigVersion.cmake + VERSION "${POTDPROVIDER_VERSION}" + COMPATIBILITY SameMajorVersion +) + +set(CMAKECONFIG_INSTALL_DIR ${KDE_INSTALL_LIBDIR}/cmake/PlasmaPotdProvider) +configure_package_config_file(PlasmaPotdProvider.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/PlasmaPotdProviderConfig.cmake" + INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} +) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/PlasmaPotdProviderConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/PlasmaPotdProviderConfigVersion.cmake + DESTINATION ${CMAKECONFIG_INSTALL_DIR} + COMPONENT Devel +) + +install(EXPORT plasmapotdproviderTargets + NAMESPACE Plasma:: + DESTINATION ${CMAKECONFIG_INSTALL_DIR} + FILE PlasmaPotdProviderTargets.cmake + COMPONENT Devel +) ########### plugins ############### diff --git a/dataengines/potd/PlasmaPotdProvider.cmake.in b/dataengines/potd/PlasmaPotdProvider.cmake.in new file mode 100644 --- /dev/null +++ b/dataengines/potd/PlasmaPotdProvider.cmake.in @@ -0,0 +1,7 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) +find_dependency(Qt5Gui "@QT_MIN_VERSION@") +find_dependency(KF5CoreAddons "@KF5_MIN_VERSION@") + +include("${CMAKE_CURRENT_LIST_DIR}/PlasmaPotdProviderTargets.cmake") diff --git a/templates/CMakeLists.txt b/templates/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/templates/CMakeLists.txt @@ -0,0 +1,5 @@ +set(apptemplate_DIRS + plasmapotdprovider +) + +kde_package_app_templates(TEMPLATES ${apptemplate_DIRS} INSTALL_DIR ${KDE_INSTALL_KTEMPLATESDIR}) diff --git a/templates/plasmapotdprovider/CMakeLists.txt b/templates/plasmapotdprovider/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/templates/plasmapotdprovider/CMakeLists.txt @@ -0,0 +1,34 @@ +cmake_minimum_required(VERSION 3.0) + +project(%{APPNAMEID}) + +set(QT_MIN_VERSION "5.9.0") +set(KF5_MIN_VERSION "5.42.0") + +find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) +set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) + +find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED + COMPONENTS + Core +) + +find_package(KF5 ${KF5_MIN_VERSION} REQUIRED + COMPONENTS + KIO +) + +find_package(PlasmaPotdProvider CONFIG) +set_package_properties(PlasmaPotdProvider PROPERTIES + DESCRIPTION "Plasma Picture-of-the-day Provider library" + TYPE REQUIRED +) + +include(KDEInstallDirs) +include(KDECMakeSettings) +include(KDECompilerSettings NO_POLICY_SCOPE) +include(FeatureSummary) + +add_subdirectory(src) + +feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/templates/plasmapotdprovider/README b/templates/plasmapotdprovider/README new file mode 100644 --- /dev/null +++ b/templates/plasmapotdprovider/README @@ -0,0 +1,29 @@ +Plasma Picture-Of-The-Day Provider +---------------------------------- + +-- Note -- + +Remember that this potd plugin relies on a semi-public API, +as exposed by the "plasma/potdprovider/potdprovider.h" header. +While this API has been the same for some time, there is no guarantee +that it will be stable for all future versions of the potd dataengine +as part of Plasma Addons. + +The main purpose of having this interface semi-public is to allow everyone +to easily develop adapters to more potd providers, +without needing to work directly in the module kdeplasma-addons. + +Once your potd plugin is nicely working, please consider to propose it +for inclusion with in the KDE module kdeplasma-addons with the existing potd providers. + + +-- Build instructions -- + +cd /where/your/potdprovider/is/generated +mkdir build +cd build +cmake -DCMAKE_INSTALL_PREFIX=MYPREFIX .. +make +make install + +(MYPREFIX is where you install your Plasma setup, replace it accordingly) diff --git a/templates/plasmapotdprovider/plasmapotdprovider.kdevtemplate b/templates/plasmapotdprovider/plasmapotdprovider.kdevtemplate new file mode 100644 --- /dev/null +++ b/templates/plasmapotdprovider/plasmapotdprovider.kdevtemplate @@ -0,0 +1,6 @@ +[General] +Name=Plasma Picture-of-the-Day Provider +Comment=A provider for the Plasma Picture-of-the-day dataengine, providing access to one image service + +ShowFilesAfterGeneration=src/%{APPNAMELC}.cpp +Category=Plasma/Dataengine diff --git a/templates/plasmapotdprovider/src/%{APPNAMELC}.h b/templates/plasmapotdprovider/src/%{APPNAMELC}.h new file mode 100644 --- /dev/null +++ b/templates/plasmapotdprovider/src/%{APPNAMELC}.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}> * + * + * 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 %{APPNAMEUC}_H +#define %{APPNAMEUC}_H + +#include +// Qt +#include + +class KJob; + +class %{APPNAME} : public PotdProvider +{ + Q_OBJECT + +public: + /** + * Creates a new %{APPNAME}. + * + * @param parent the parent object + * @param args arguments from the plugin factory (unused) + */ + %{APPNAME}(QObject *parent, const QVariantList &args); + + /** + * Destroys the provider. + */ + ~%{APPNAME}() override; + + /** + * Returns the requested image. + */ + QImage image() const override; + +private: + void handleFinishedFeedRequest(KJob *job); + void handleFinishedImageRequest(KJob *job); + +private: + QImage mImage; +}; + +#endif diff --git a/templates/plasmapotdprovider/src/%{APPNAMELC}.cpp b/templates/plasmapotdprovider/src/%{APPNAMELC}.cpp new file mode 100644 --- /dev/null +++ b/templates/plasmapotdprovider/src/%{APPNAMELC}.cpp @@ -0,0 +1,85 @@ +/* + * Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}> * + * + * 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 "%{APPNAMELC}.h" + +// KF +#include +#include + + +%{APPNAME}::%{APPNAME}(QObject *parent, const QVariantList &args) + : PotdProvider(parent, args) +{ + // TODO: replace with url to data about what the current picture of the day is + const QUrl potdFeed(QStringLiteral("https://kde.org")); + + KIO::StoredTransferJob* job = KIO::storedGet(potdFeed, KIO::NoReload, KIO::HideProgressInfo); + connect(job, &KIO::StoredTransferJob::finished, + this, &%{APPNAME}::handleFinishedFeedRequest); +} + +%{APPNAME}::~%{APPNAME}() +{ +} + +QImage %{APPNAME}::image() const +{ + return mImage; +} + +void %{APPNAME}::handleFinishedFeedRequest(KJob *job) +{ + KIO::StoredTransferJob *requestJob = static_cast(job); + if (requestJob->error()) { + emit error(this); + return; + } + + // TODO: read url to image from requestJob->data() + const QUrl picureUrl(QStringLiteral("https://techbase.kde.org/favicon.png")); + + KIO::StoredTransferJob *imageJob = KIO::storedGet(picureUrl, KIO::NoReload, KIO::HideProgressInfo); + connect(imageJob, &KIO::StoredTransferJob::finished, + this, &%{APPNAME}::handleFinishedImageRequest); +} + +void %{APPNAME}::handleFinishedImageRequest(KJob *job) +{ + KIO::StoredTransferJob *requestJob = static_cast(job); + if (requestJob->error()) { + emit error(this); + return; + } + + mImage = QImage::fromData(requestJob->data()); + + if (mImage.isNull()) { + emit error(this); + return; + } + + emit finished(this); +} + + +K_PLUGIN_FACTORY_WITH_JSON(%{APPNAME}Factory, "%{APPNAMELC}.json", + registerPlugin<%{APPNAME}>();) + +#include "%{APPNAMELC}.moc" diff --git a/templates/plasmapotdprovider/src/%{APPNAMELC}.json b/templates/plasmapotdprovider/src/%{APPNAMELC}.json new file mode 100644 --- /dev/null +++ b/templates/plasmapotdprovider/src/%{APPNAMELC}.json @@ -0,0 +1,16 @@ +{ + "KPlugin": { + "Authors": [ + { + "Email": "%{EMAIL}", + "Name": "%{AUTHOR}" + } + ], + "Description": "%{APPNAME}", + "Name": "%{APPNAME}", + "ServiceTypes": [ + "PlasmaPoTD/Plugin" + ] + }, + "X-KDE-PlasmaPoTDProvider-Identifier": "%{APPNAMELC}" +} diff --git a/templates/plasmapotdprovider/src/CMakeLists.txt b/templates/plasmapotdprovider/src/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/templates/plasmapotdprovider/src/CMakeLists.txt @@ -0,0 +1,11 @@ +set(potd_%{APPNAMELC}_SRCS + %{APPNAMELC}.cpp +) + +add_library(plasma_potd_%{APPNAMELC} MODULE ${potd_%{APPNAMELC}_SRCS}) +target_link_libraries(plasma_potd_%{APPNAMELC} + Plasma::PotdProvider + KF5::KIOCore +) + +install(TARGETS plasma_potd_%{APPNAMELC} DESTINATION ${KDE_INSTALL_PLUGINDIR}/potd)