Commit da8905fd authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

[potd dataengine] Enable development of 3rd-party potd provider plugins

Summary:
Installing the headers of libplasmapotdprovidercore in the include namespace
	plasma/potdprovider
as well as some CMake Config files of the name
	PlasmaPotdProvider
allows it 3rd-party to develop own potd provider plugins without having
to mess with the complete kdeplasma-addons repo.

A potd-provider plugin template in kapptemplate format should speed up
development of new plugins some more.

Test Plan:
Generated a new plugin from the template, built and installed it, selected
it in the POTD wallpaper and got the KDE logo as fetched from techbase
shown.

Reviewers: xuetianweng

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D11964
parent 7f9d71b7
......@@ -22,7 +22,9 @@ include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(ECMQtDeclareLoggingCategory)
include(ECMInstallIcons)
include(KDEPackageAppTemplates)
include(GenerateExportHeader)
include(CMakePackageConfigHelpers)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED
Core
......@@ -84,4 +86,6 @@ add_subdirectory(wallpapers)
add_subdirectory(windowswitchers)
add_subdirectory(desktopswitchers)
add_subdirectory(templates)
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
......@@ -16,6 +16,8 @@ install(FILES plasma-dataengine-potd.desktop DESTINATION ${KDE_INSTALL_KSERVICES
########### plugin core library ############
set(POTDPROVIDER_VERSION 1.0.0)
set(POTDPROVIDER_VERSION_MAJOR 1)
set(potd_provider_core_SRCS
potdprovider.cpp
......@@ -23,11 +25,51 @@ set(potd_provider_core_SRCS
)
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 "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>"
INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR}>"
)
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 ###############
......
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(Qt5Gui "@QT_MIN_VERSION@")
find_dependency(KF5CoreAddons "@KF5_MIN_VERSION@")
include("${CMAKE_CURRENT_LIST_DIR}/PlasmaPotdProviderTargets.cmake")
set(apptemplate_DIRS
plasmapotdprovider
)
kde_package_app_templates(TEMPLATES ${apptemplate_DIRS} INSTALL_DIR ${KDE_INSTALL_KTEMPLATESDIR})
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)
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)
[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
/*
* 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 <KPluginFactory>
#include <KIO/Job>
%{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<KIO::StoredTransferJob*>(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<KIO::StoredTransferJob*>(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"
/*
* 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 <plasma/potdprovider/potdprovider.h>
// Qt
#include <QImage>
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
{
"KPlugin": {
"Authors": [
{
"Email": "%{EMAIL}",
"Name": "%{AUTHOR}"
}
],
"Description": "%{APPNAME}",
"Name": "%{APPNAME}",
"ServiceTypes": [
"PlasmaPoTD/Plugin"
]
},
"X-KDE-PlasmaPoTDProvider-Identifier": "%{APPNAMELC}"
}
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)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment