Skip to content

Commit d031239

Browse files
committed
refactor qml plugin
* Port to ecm_add_qml_module * Use declarative type registration * Update URI * Remove redundant creation DayNight object in settings page
1 parent b22a85b commit d031239

9 files changed

Lines changed: 42 additions & 46 deletions

File tree

package/contents/ui/DayNightCycleController.qml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ Item {
5050
if (component.status === Component.Ready) {
5151
dayNightPlugin = component.createObject(root);
5252
dayNightPlugin.initialState = root.darkLightScheduleState;
53-
dayNightPlugin.stateChanged.connect(() => {
54-
if (root.darkLightScheduleState != dayNightPlugin.state) {
55-
root.darkLightScheduleState = dayNightPlugin.state;
53+
dayNightPlugin.scheduleStateChanged.connect(() => {
54+
if (root.darkLightScheduleState != dayNightPlugin.scheduleState) {
55+
root.darkLightScheduleState = dayNightPlugin.scheduleState;
5656
}
5757
});
5858
} else {

package/contents/ui/DayNightCyclePlugin.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import QtQuick
2-
import com.github.luisbocanegra.svwr.nighttime 1.0
2+
import com.github.luisbocanegra.svwr 1.0
33

44
Item {
55
readonly property alias phase: dayNight.phase
6-
readonly property alias state: dayNight.state
6+
readonly property alias scheduleState: dayNight.state
77
property alias initialState: dayNight.initialState
88
DayNight {
99
id: dayNight

package/contents/ui/config.qml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ ColumnLayout {
8585
property alias cfg_MuteMode: muteModeCombo.currentValue
8686
property int editingIndex: -1
8787
property var validDropExtensions: [".mp4", ".mpg", ".ogg", ".mov", ".webm", ".flv", ".mkv", ".avi", ".wmv", ".gif"]
88-
property var dayNightPlugin: null
8988
property bool showCustomTimeControls: false
9089
property string cfg_DarkLightScheduleState
9190

@@ -247,11 +246,6 @@ ColumnLayout {
247246
Component.onCompleted: {
248247
videosModel.initModel(cfg_VideoUrls);
249248
getAudioDevicesModel();
250-
try {
251-
dayNightPlugin = Qt.createQmlObject("import com.github.luisbocanegra.svwr.nighttime 1.0; DayNight {}", root);
252-
} catch (e) {
253-
console.warn("QML Plugin com.github.luisbocanegra.svwr.nighttime not found, will use fixed times");
254-
}
255249
}
256250

257251
Kirigami.FormLayout {
@@ -453,7 +447,7 @@ ColumnLayout {
453447
}
454448
Button {
455449
visible: root.cfg_DayNightCycleMode == Enum.DayNightCycleMode.DayNightCycle
456-
enabled: KConfig.KAuthorized.authorizeControlModule("kcm_nighttime") && root.dayNightPlugin !== null
450+
enabled: KConfig.KAuthorized.authorizeControlModule("kcm_nighttime") && dayNightCycleController.dayNightPlugin !== null
457451
text: i18ndc("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "@action:button Configure day-night cycle times", "Configure…")
458452
icon.name: "configure"
459453
onClicked: KCM.KCMLauncher.open("kcm_nighttime")
@@ -471,7 +465,7 @@ ColumnLayout {
471465
}
472466
Label {
473467
id: dayNightCyclePluginWarning
474-
visible: root.currentTab === 0 && root.cfg_DayNightCycleMode == Enum.DayNightCycleMode.DayNightCycle && root.dayNightPlugin === null
468+
visible: root.currentTab === 0 && root.cfg_DayNightCycleMode == Enum.DayNightCycleMode.DayNightCycle && dayNightCycleController.dayNightPlugin === null
475469
color: Kirigami.Theme.negativeTextColor
476470
text: i18nd("plasma_wallpaper_luisbocanegra.smart.video.wallpaper.reborn", "⚠ The C++ plugin is not available, this feature will not work. Switch to the Smart Video Wallpaper Reborn package for your distribution if available, or build the plugin from source. See <a href='%1'>install instructions</a>.", "https://github.com/luisbocanegra/plasma-smart-video-wallpaper-reborn#installing")
477471
wrapMode: Label.WordWrap

plugin/CMakeLists.txt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
1-
set(PLUGIN_NAME "nighttimeplugin")
2-
set(LIB_NAME "nighttime")
3-
4-
add_library(${PLUGIN_NAME} SHARED ${PLUGIN_NAME}.cpp ${LIB_NAME}.cpp)
5-
find_package(Qt6 ${QT_MIN_VERSION} REQUIRED COMPONENTS Qml Gui)
1+
include(ECMQmlModule)
2+
find_package(Qt6 ${QT_MIN_VERSION} REQUIRED COMPONENTS Qml)
63
find_package(KNightTime ${PROJECT_DEP_VERSION} CONFIG REQUIRED)
74
find_package(KF6 ${KF6_MIN_VERSION} REQUIRED COMPONENTS KCMUtils)
85

9-
target_link_libraries(${PLUGIN_NAME}
6+
set(daynight_SRCS
7+
daynight.cpp daynight.h
8+
)
9+
10+
add_library(plasma_wallpaper_svw_static STATIC ${daynight_SRCS})
11+
set_property(TARGET plasma_wallpaper_svw_static PROPERTY POSITION_INDEPENDENT_CODE ON)
12+
13+
target_link_libraries(plasma_wallpaper_svw_static
1014
Qt6::Qml
11-
Qt6::Gui
1215
KF6::KCMUtils
1316
KNightTime
1417
)
1518

16-
install(TARGETS ${PLUGIN_NAME} DESTINATION ${KDE_INSTALL_QMLDIR}/com/github/luisbocanegra/svwr/${LIB_NAME})
17-
install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/com/github/luisbocanegra/svwr/${LIB_NAME})
19+
ecm_add_qml_module(plasma_wallpaper_svw URI "com.github.luisbocanegra.svwr" VERSION 1.0 CLASS_NAME DayNight)
20+
21+
qt_generate_foreign_qml_types(plasma_wallpaper_svw_static plasma_wallpaper_svw)
22+
23+
target_sources(plasma_wallpaper_svw PRIVATE smartvideowallpaperplugin.cpp)
24+
25+
target_link_libraries(plasma_wallpaper_svw PRIVATE
26+
plasma_wallpaper_svw_static
27+
)
28+
29+
ecm_finalize_qml_module(plasma_wallpaper_svw)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
SPDX-License-Identifier: GPL-2.0-or-later
66
*/
77

8-
#include "nighttime.h"
8+
#include "daynight.h"
99

1010
DayNightPhase::DayNightPhase()
1111
: m_kind(Night)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
SPDX-License-Identifier: GPL-2.0-or-later
66
*/
77

8-
#ifndef NIGHTTIME_H
9-
#define NIGHTTIME_H
8+
#ifndef DAYNIGHT_H
9+
#define DAYNIGHT_H
1010

1111
#pragma once
1212
#include <KDarkLightScheduleProvider>

plugin/nighttimeplugin.cpp

Lines changed: 0 additions & 19 deletions
This file was deleted.

plugin/qmldir

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <QQmlEngine>
2+
#include <QQmlExtensionPlugin>
3+
#include <qqmlextensionplugin.h>
4+
5+
class DayNightPlugin : public QQmlEngineExtensionPlugin
6+
{
7+
Q_OBJECT
8+
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
9+
};
10+
11+
#include "smartvideowallpaperplugin.moc"

0 commit comments

Comments
 (0)