diff --git a/templates/CMakeLists.txt b/templates/CMakeLists.txt --- a/templates/CMakeLists.txt +++ b/templates/CMakeLists.txt @@ -3,6 +3,7 @@ qml-plasmoid-with-qml-extension cpp-plasmoid plasma-wallpaper + plasma-wallpaper-with-qml-extension ) kde_package_app_templates(TEMPLATES ${apptemplate_DIRS} INSTALL_DIR ${KDE_INSTALL_KTEMPLATESDIR}) diff --git a/templates/plasma-wallpaper-with-qml-extension/CMakeLists.txt b/templates/plasma-wallpaper-with-qml-extension/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/templates/plasma-wallpaper-with-qml-extension/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.0) + +project(plasma-%{APPNAMELC}) + +find_package(ECM 1.4.0 REQUIRED NO_MODULE) +set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) + +include(KDEInstallDirs) +include(KDECMakeSettings) +include(KDECompilerSettings NO_POLICY_SCOPE) +include(FeatureSummary) + +find_package(KF5 REQUIRED COMPONENTS + Plasma + I18n +) + +find_package(Qt5 CONFIG REQUIRED COMPONENTS + Qml + Gui + Core +) + +# wallpaper applet +plasma_install_package(package org.kde.plasma.%{APPNAMELC} wallpapers wallpaper) + +# qml extension plugin +add_subdirectory(plugin) + +feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/templates/plasma-wallpaper-with-qml-extension/Messages.sh b/templates/plasma-wallpaper-with-qml-extension/Messages.sh new file mode 100644 --- /dev/null +++ b/templates/plasma-wallpaper-with-qml-extension/Messages.sh @@ -0,0 +1,2 @@ +#! /usr/bin/env bash +$XGETTEXT `find . -name \*.qml -o -name \*.cpp` -o $podir/plasma_wallpaper_org.kde.plasma.%{APPNAMELC}.pot diff --git a/templates/plasma-wallpaper-with-qml-extension/README b/templates/plasma-wallpaper-with-qml-extension/README new file mode 100644 --- /dev/null +++ b/templates/plasma-wallpaper-with-qml-extension/README @@ -0,0 +1,24 @@ +Plasma Wallpaper Template +---------------------- + +-- Build instructions -- + +cd /where/your/wallpaper/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) + +Restart plasma to load the wallpaper +(in a terminal or in krunner type: +kquitapp plasmashell +and then +plasmashell) +then go to wallpaper settings and select it + +-- Tutorials and resources -- +Plasma QML API explained +https://techbase.kde.org/Development/Tutorials/Plasma2/QML2/API diff --git a/templates/plasma-wallpaper-with-qml-extension/package/contents/config/main.xml b/templates/plasma-wallpaper-with-qml-extension/package/contents/config/main.xml new file mode 100644 --- /dev/null +++ b/templates/plasma-wallpaper-with-qml-extension/package/contents/config/main.xml @@ -0,0 +1,15 @@ + + + + + + + + Hello World! + + + + diff --git a/templates/plasma-wallpaper-with-qml-extension/package/contents/ui/config.qml b/templates/plasma-wallpaper-with-qml-extension/package/contents/ui/config.qml new file mode 100644 --- /dev/null +++ b/templates/plasma-wallpaper-with-qml-extension/package/contents/ui/config.qml @@ -0,0 +1,56 @@ +/* + * 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 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. + */ + +import QtQuick 2.1 +import QtQuick.Layouts 1.0 +import QtQuick.Controls 1.0 as QtControls + +// for "units" +import org.kde.plasma.core 2.0 as PlasmaCore + + +ColumnLayout { + id: root + property alias cfg_DisplayText: textField.text + + RowLayout { + spacing: units.largeSpacing / 2 + + // To allow aligned integration in the settings form, + // "formAlignment" is a property injected by the config containment + // which defines the offset of the value fields + QtControls.Label { + Layout.minimumWidth: width + Layout.maximumWidth: width + width: formAlignment - units.largeSpacing + horizontalAlignment: Text.AlignRight + + // use i18nd in config QML, as the default textdomain is set to that of the config container + text: i18nd("plasma_wallpaper_org.kde.plasma.%{APPNAMELC}", "Text to Display:") + } + QtControls.TextField { + id: textField + Layout.fillWidth: true + } + } + + Item { // tighten layout + Layout.fillHeight: true + } +} diff --git a/templates/plasma-wallpaper-with-qml-extension/package/contents/ui/main.qml b/templates/plasma-wallpaper-with-qml-extension/package/contents/ui/main.qml new file mode 100644 --- /dev/null +++ b/templates/plasma-wallpaper-with-qml-extension/package/contents/ui/main.qml @@ -0,0 +1,46 @@ +/* + * 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 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. + */ + +import QtQuick 2.1 + +import QtQuick.Layouts 1.1 + +import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.plasma.extras 2.0 as PlasmaExtras + +import org.kde.plasma.private.%{APPNAMELC} 1.0 + +Item { + id: root + + ColumnLayout { + anchors.centerIn: parent + + PlasmaExtras.Title { + Layout.alignment: Qt.AlignCenter + text: wallpaper.configuration.DisplayText || + i18n("") + } + + PlasmaComponents.Label { + Layout.alignment: Qt.AlignCenter + text: HelloWorld.text + } + } +} diff --git a/templates/plasma-wallpaper-with-qml-extension/package/metadata.desktop b/templates/plasma-wallpaper-with-qml-extension/package/metadata.desktop new file mode 100644 --- /dev/null +++ b/templates/plasma-wallpaper-with-qml-extension/package/metadata.desktop @@ -0,0 +1,14 @@ +[Desktop Entry] +Name=%{APPNAME} + +Type=Service +Icon=plasma + +X-KDE-ServiceTypes=Plasma/Wallpaper +X-KDE-PluginInfo-Author=%{AUTHOR} +X-KDE-PluginInfo-Email=%{EMAIL} +X-KDE-PluginInfo-Name=org.kde.plasma.%{APPNAMELC} +X-KDE-PluginInfo-License=LGPLv2+ +X-KDE-PluginInfo-Version=%{VERSION} +X-KDE-PluginInfo-Website=https://plasma.kde.org/ +X-Plasma-MainScript=ui/main.qml diff --git a/templates/plasma-wallpaper-with-qml-extension/plasma-wallpaper-with-qml-extension.kdevtemplate b/templates/plasma-wallpaper-with-qml-extension/plasma-wallpaper-with-qml-extension.kdevtemplate new file mode 100644 --- /dev/null +++ b/templates/plasma-wallpaper-with-qml-extension/plasma-wallpaper-with-qml-extension.kdevtemplate @@ -0,0 +1,5 @@ +[General] +Name=Simple Plasma Wallpaper with QML extension +Comment=A Plasma wallpaper which uses custom API provided by an own QML extension plugin +Category=Plasma/Wallpaper +Icon= diff --git a/templates/plasma-wallpaper-with-qml-extension/plugin/%{APPNAMELC}plugin.h b/templates/plasma-wallpaper-with-qml-extension/plugin/%{APPNAMELC}plugin.h new file mode 100644 --- /dev/null +++ b/templates/plasma-wallpaper-with-qml-extension/plugin/%{APPNAMELC}plugin.h @@ -0,0 +1,33 @@ +/* + * 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 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 %{APPNAMEUC}PLUGIN_H +#define %{APPNAMEUC}PLUGIN_H + +#include + +class %{APPNAME}Plugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) override; +}; + +#endif // %{APPNAMEUC}PLUGIN_H diff --git a/templates/plasma-wallpaper-with-qml-extension/plugin/%{APPNAMELC}plugin.cpp b/templates/plasma-wallpaper-with-qml-extension/plugin/%{APPNAMELC}plugin.cpp new file mode 100644 --- /dev/null +++ b/templates/plasma-wallpaper-with-qml-extension/plugin/%{APPNAMELC}plugin.cpp @@ -0,0 +1,43 @@ +/* + * 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 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 "%{APPNAMELC}plugin.h" + +// KF +#include +// Qt +#include +#include +#include + +static QJSValue singletonTypeExampleProvider(QQmlEngine* engine, QJSEngine* scriptEngine) +{ + Q_UNUSED(engine) + + QJSValue helloWorld = scriptEngine->newObject(); + helloWorld.setProperty("text", i18n("Hello world!")); + return helloWorld; +} + + +void %{APPNAME}Plugin::registerTypes(const char* uri) +{ + Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.%{APPNAMELC}")); + + qmlRegisterSingletonType(uri, 1, 0, "HelloWorld", singletonTypeExampleProvider); +} diff --git a/templates/plasma-wallpaper-with-qml-extension/plugin/CMakeLists.txt b/templates/plasma-wallpaper-with-qml-extension/plugin/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/templates/plasma-wallpaper-with-qml-extension/plugin/CMakeLists.txt @@ -0,0 +1,15 @@ +add_definitions(-DTRANSLATION_DOMAIN=\"plasma_wallpaper_org.kde.plasma.%{APPNAMELC}\") + +set(%{APPNAMELC}plugin_SRCS + %{APPNAMELC}plugin.cpp +) + +add_library(%{APPNAMELC}plugin SHARED ${%{APPNAMELC}plugin_SRCS}) + +target_link_libraries(%{APPNAMELC}plugin + KF5::I18n + Qt5::Gui + Qt5::Qml +) +install(TARGETS %{APPNAMELC}plugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/%{APPNAMELC}) +install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/%{APPNAMELC}) diff --git a/templates/plasma-wallpaper-with-qml-extension/plugin/qmldir b/templates/plasma-wallpaper-with-qml-extension/plugin/qmldir new file mode 100644 --- /dev/null +++ b/templates/plasma-wallpaper-with-qml-extension/plugin/qmldir @@ -0,0 +1,2 @@ +module org.kde.plasma.private.%{APPNAMELC} +plugin %{APPNAMELC}plugin