Add template for Plasma wallpaper with QML extension

Summary:
Allows to quickly start a new wallpaper which also wants to use a custom QML
extension.

Reviewers: mart

Reviewed By: mart

Subscribers: #frameworks

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D10849
This commit is contained in:
Friedrich W. H. Kossebau 2018-02-26 07:15:25 +01:00
parent d93ecddd14
commit 354bd71296
13 changed files with 286 additions and 0 deletions

View File

@ -3,6 +3,7 @@ set(apptemplate_DIRS
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})

View File

@ -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)

View File

@ -0,0 +1,2 @@
#! /usr/bin/env bash
$XGETTEXT `find . -name \*.qml -o -name \*.cpp` -o $podir/plasma_wallpaper_org.kde.plasma.%{APPNAMELC}.pot

View File

@ -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

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile name=""/>
<group name="General">
<entry name="DisplayText" type="String">
<label>Text to display</label>
<default>Hello World!</default>
</entry>
</group>
</kcfg>

View File

@ -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
}
}

View File

@ -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("<Please configure a text to display>")
}
PlasmaComponents.Label {
Layout.alignment: Qt.AlignCenter
text: HelloWorld.text
}
}
}

View File

@ -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

View File

@ -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=

View File

@ -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 <KLocalizedString>
// Qt
#include <QJSEngine>
#include <QQmlEngine>
#include <QQmlContext>
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);
}

View File

@ -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 <QQmlExtensionPlugin>
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

View File

@ -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})

View File

@ -0,0 +1,2 @@
module org.kde.plasma.private.%{APPNAMELC}
plugin %{APPNAMELC}plugin