From 4f74b09192076346c3fc3c92bab65fc192d28c0c Mon Sep 17 00:00:00 2001 From: reionwong Date: Wed, 28 Jul 2021 02:40:45 +0800 Subject: [PATCH] Add system module --- CMakeLists.txt | 1 + system/CMakeLists.txt | 19 +++++++++++++++++++ system/plugin.cpp | 17 +++++++++++++++++ system/qmldir | 3 +++ system/wallpaper.cpp | 24 ++++++++++++++++++++++++ system/wallpaper.h | 28 ++++++++++++++++++++++++++++ 6 files changed, 92 insertions(+) create mode 100644 system/CMakeLists.txt create mode 100644 system/plugin.cpp create mode 100644 system/qmldir create mode 100644 system/wallpaper.cpp create mode 100644 system/wallpaper.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 32cfde6..af9df65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,3 +38,4 @@ add_subdirectory(bluez) add_subdirectory(mpris) add_subdirectory(networkmanagement) add_subdirectory(screen) +add_subdirectory(system) diff --git a/system/CMakeLists.txt b/system/CMakeLists.txt new file mode 100644 index 0000000..2b4f284 --- /dev/null +++ b/system/CMakeLists.txt @@ -0,0 +1,19 @@ +set(SCREEN_SRCS + wallpaper.cpp + wallpaper.h + plugin.cpp +) + +find_package(Qt5 REQUIRED COMPONENTS DBus) + +add_library(cutefishsystem_qmlplugins SHARED ${SCREEN_SRCS}) + +target_link_libraries (cutefishsystem_qmlplugins + Qt5::Core + Qt5::Quick + Qt5::Gui + Qt5::DBus +) + +install(TARGETS cutefishsystem_qmlplugins DESTINATION ${INSTALL_QMLDIR}/Cutefish/System) +install(FILES qmldir DESTINATION ${INSTALL_QMLDIR}/Cutefish/System) \ No newline at end of file diff --git a/system/plugin.cpp b/system/plugin.cpp new file mode 100644 index 0000000..5dfb068 --- /dev/null +++ b/system/plugin.cpp @@ -0,0 +1,17 @@ +#include +#include + +#include "wallpaper.h" + +class QmlPlugins : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char * uri) override { + qmlRegisterType(uri, 1, 0, "Wallpaper"); + } +}; + +#include "plugin.moc" \ No newline at end of file diff --git a/system/qmldir b/system/qmldir new file mode 100644 index 0000000..3ec350a --- /dev/null +++ b/system/qmldir @@ -0,0 +1,3 @@ +module Cutefish.System + +plugin cutefishsystem_qmlplugins \ No newline at end of file diff --git a/system/wallpaper.cpp b/system/wallpaper.cpp new file mode 100644 index 0000000..99d0a63 --- /dev/null +++ b/system/wallpaper.cpp @@ -0,0 +1,24 @@ +#include "wallpaper.h" + +Wallpaper::Wallpaper(QObject *parent) + : QObject(parent) + , m_interface("org.cutefish.Settings", + "/Theme", "org.cutefish.Theme", + QDBusConnection::sessionBus(), this) +{ + if (m_interface.isValid()) { + connect(&m_interface, SIGNAL(wallpaperChanged(QString)), this, SLOT(onPathChanged(QString))); + } +} + +QString Wallpaper::path() const +{ + return m_interface.property("wallpaper").toString(); +} + +void Wallpaper::onPathChanged(QString path) +{ + Q_UNUSED(path); + + emit pathChanged(); +} diff --git a/system/wallpaper.h b/system/wallpaper.h new file mode 100644 index 0000000..a5cc372 --- /dev/null +++ b/system/wallpaper.h @@ -0,0 +1,28 @@ +#ifndef WALLPAPER_H +#define WALLPAPER_H + +#include +#include + +class Wallpaper : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString path READ path NOTIFY pathChanged) + +public: + explicit Wallpaper(QObject *parent = nullptr); + + QString path() const; + +signals: + void pathChanged(); + +private slots: + void onPathChanged(QString path); + +private: + QDBusInterface m_interface; + QString m_wallpaper; +}; + +#endif // WALLPAPER_H