1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
// SPDX-FileCopyrightText: 2023 Méven Car <meven@kde.org>
// SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <QObject>
#include <QQmlPropertyMap>
#include <QQuickItem>
#include <qqmlregistration.h>
#include <KConfig>
#include <KConfigGroup>
#include <KConfigLoader>
#include <KConfigPropertyMap>
#include <KConfigWatcher>
#include <PlasmaQuick/ConfigModel>
#include <QCoroDBusPendingReply>
class WallpaperConfigModel;
class WallpaperPlugin : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
Q_PROPERTY(QString homescreenWallpaperPath READ homescreenWallpaperPath NOTIFY homescreenWallpaperPathChanged)
Q_PROPERTY(QString lockscreenWallpaperPath READ lockscreenWallpaperPath NOTIFY lockscreenWallpaperPathChanged)
Q_PROPERTY(QQmlPropertyMap *homescreenConfiguration READ homescreenConfiguration NOTIFY homescreenConfigurationChanged)
Q_PROPERTY(QQmlPropertyMap *lockscreenConfiguration READ lockscreenConfiguration NOTIFY lockscreenConfigurationChanged)
Q_PROPERTY(PlasmaQuick::ConfigModel *wallpaperPluginModel READ wallpaperPluginModel CONSTANT)
Q_PROPERTY(QString homescreenWallpaperPlugin READ homescreenWallpaperPlugin WRITE setHomescreenWallpaperPlugin NOTIFY homescreenWallpaperPluginChanged)
Q_PROPERTY(QString homescreenWallpaperPluginSource READ homescreenWallpaperPluginSource NOTIFY homescreenWallpaperPluginChanged)
Q_PROPERTY(QString lockscreenWallpaperPlugin READ lockscreenWallpaperPlugin WRITE setLockscreenWallpaperPlugin NOTIFY lockscreenWallpaperPluginChanged)
Q_PROPERTY(QString lockscreenWallpaperPluginSource READ lockscreenWallpaperPluginSource NOTIFY lockscreenWallpaperPluginChanged)
public:
WallpaperPlugin(QObject *parent = nullptr);
PlasmaQuick::ConfigModel *wallpaperPluginModel();
QQmlPropertyMap *homescreenConfiguration() const;
QQmlPropertyMap *lockscreenConfiguration() const;
QString homescreenWallpaperPlugin() const;
QString homescreenWallpaperPluginSource();
Q_INVOKABLE void setHomescreenWallpaperPlugin(const QString &wallpaperPlugin);
QString lockscreenWallpaperPlugin() const;
QString lockscreenWallpaperPluginSource();
Q_INVOKABLE void setLockscreenWallpaperPlugin(const QString &wallpaperPlugin);
// changes the plugin to org.kde.image and sets an image
Q_INVOKABLE QCoro::Task<void> setHomescreenWallpaper(const QString &path);
Q_INVOKABLE void setLockscreenWallpaper(const QString &path);
QString homescreenWallpaperPath();
QString lockscreenWallpaperPath();
Q_INVOKABLE QCoro::Task<void> saveHomescreenSettings();
Q_INVOKABLE void saveLockscreenSettings();
public Q_SLOTS:
QCoro::Task<void> loadHomescreenSettings();
void loadLockscreenSettings();
Q_SIGNALS:
void homescreenWallpaperPathChanged();
void lockscreenWallpaperPathChanged();
void homescreenConfigurationChanged();
void lockscreenConfigurationChanged();
void currentWallpaperPluginChanged();
void homescreenWallpaperPluginChanged();
void lockscreenWallpaperPluginChanged();
private:
QQmlPropertyMap *loadConfiguration(KConfigGroup group, QString wallpaperPlugin, bool loadDefaults);
QString m_homescreenWallpaperPlugin;
QString m_lockscreenWallpaperPlugin;
QString m_homescreenWallpaperPath;
QString m_lockscreenWallpaperPath;
QQmlPropertyMap *m_homescreenConfig{nullptr};
QQmlPropertyMap *m_lockscreenConfig{nullptr};
KSharedConfig::Ptr m_homescreenConfigFile{nullptr};
KSharedConfig::Ptr m_lockscreenConfigFile{nullptr};
KConfigWatcher::Ptr m_lockscreenConfigWatcher{nullptr};
WallpaperConfigModel *m_wallpaperPluginModel = nullptr;
};
class WallpaperConfigModel : public PlasmaQuick::ConfigModel
{
Q_OBJECT
public:
WallpaperConfigModel(QObject *parent);
public Q_SLOTS:
void repopulate();
};
|