File indexing completed on 2024-05-12 05:36:10

0001 // SPDX-FileCopyrightText: 2023 Méven Car <meven@kde.org>
0002 // SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 #pragma once
0006 
0007 #include <QObject>
0008 #include <QQmlPropertyMap>
0009 #include <QQuickItem>
0010 #include <qqmlregistration.h>
0011 
0012 #include <KConfig>
0013 #include <KConfigGroup>
0014 #include <KConfigLoader>
0015 #include <KConfigPropertyMap>
0016 #include <KConfigWatcher>
0017 
0018 #include <PlasmaQuick/ConfigModel>
0019 
0020 #include <QCoroDBusPendingReply>
0021 
0022 class WallpaperConfigModel;
0023 class WallpaperPlugin : public QObject
0024 {
0025     Q_OBJECT
0026     QML_ELEMENT
0027     QML_SINGLETON
0028 
0029     Q_PROPERTY(QString homescreenWallpaperPath READ homescreenWallpaperPath NOTIFY homescreenWallpaperPathChanged)
0030     Q_PROPERTY(QString lockscreenWallpaperPath READ lockscreenWallpaperPath NOTIFY lockscreenWallpaperPathChanged)
0031 
0032     Q_PROPERTY(QQmlPropertyMap *homescreenConfiguration READ homescreenConfiguration NOTIFY homescreenConfigurationChanged)
0033     Q_PROPERTY(QQmlPropertyMap *lockscreenConfiguration READ lockscreenConfiguration NOTIFY lockscreenConfigurationChanged)
0034     Q_PROPERTY(PlasmaQuick::ConfigModel *wallpaperPluginModel READ wallpaperPluginModel CONSTANT)
0035 
0036     Q_PROPERTY(QString homescreenWallpaperPlugin READ homescreenWallpaperPlugin WRITE setHomescreenWallpaperPlugin NOTIFY homescreenWallpaperPluginChanged)
0037     Q_PROPERTY(QString homescreenWallpaperPluginSource READ homescreenWallpaperPluginSource NOTIFY homescreenWallpaperPluginChanged)
0038     Q_PROPERTY(QString lockscreenWallpaperPlugin READ lockscreenWallpaperPlugin WRITE setLockscreenWallpaperPlugin NOTIFY lockscreenWallpaperPluginChanged)
0039     Q_PROPERTY(QString lockscreenWallpaperPluginSource READ lockscreenWallpaperPluginSource NOTIFY lockscreenWallpaperPluginChanged)
0040 
0041 public:
0042     WallpaperPlugin(QObject *parent = nullptr);
0043 
0044     PlasmaQuick::ConfigModel *wallpaperPluginModel();
0045     QQmlPropertyMap *homescreenConfiguration() const;
0046     QQmlPropertyMap *lockscreenConfiguration() const;
0047 
0048     QString homescreenWallpaperPlugin() const;
0049     QString homescreenWallpaperPluginSource();
0050     Q_INVOKABLE void setHomescreenWallpaperPlugin(const QString &wallpaperPlugin);
0051     QString lockscreenWallpaperPlugin() const;
0052     QString lockscreenWallpaperPluginSource();
0053     Q_INVOKABLE void setLockscreenWallpaperPlugin(const QString &wallpaperPlugin);
0054 
0055     // changes the plugin to org.kde.image and sets an image
0056     Q_INVOKABLE QCoro::Task<void> setHomescreenWallpaper(const QString &path);
0057     Q_INVOKABLE void setLockscreenWallpaper(const QString &path);
0058 
0059     QString homescreenWallpaperPath();
0060     QString lockscreenWallpaperPath();
0061 
0062     Q_INVOKABLE QCoro::Task<void> saveHomescreenSettings();
0063     Q_INVOKABLE void saveLockscreenSettings();
0064 
0065 public Q_SLOTS:
0066     QCoro::Task<void> loadHomescreenSettings();
0067     void loadLockscreenSettings();
0068 
0069 Q_SIGNALS:
0070     void homescreenWallpaperPathChanged();
0071     void lockscreenWallpaperPathChanged();
0072     void homescreenConfigurationChanged();
0073     void lockscreenConfigurationChanged();
0074     void currentWallpaperPluginChanged();
0075     void homescreenWallpaperPluginChanged();
0076     void lockscreenWallpaperPluginChanged();
0077 
0078 private:
0079     QQmlPropertyMap *loadConfiguration(KConfigGroup group, QString wallpaperPlugin, bool loadDefaults);
0080 
0081     QString m_homescreenWallpaperPlugin;
0082     QString m_lockscreenWallpaperPlugin;
0083 
0084     QString m_homescreenWallpaperPath;
0085     QString m_lockscreenWallpaperPath;
0086 
0087     QQmlPropertyMap *m_homescreenConfig{nullptr};
0088     QQmlPropertyMap *m_lockscreenConfig{nullptr};
0089 
0090     KSharedConfig::Ptr m_homescreenConfigFile{nullptr};
0091     KSharedConfig::Ptr m_lockscreenConfigFile{nullptr};
0092     KConfigWatcher::Ptr m_lockscreenConfigWatcher{nullptr};
0093 
0094     WallpaperConfigModel *m_wallpaperPluginModel = nullptr;
0095 };
0096 
0097 class WallpaperConfigModel : public PlasmaQuick::ConfigModel
0098 {
0099     Q_OBJECT
0100 
0101 public:
0102     WallpaperConfigModel(QObject *parent);
0103 public Q_SLOTS:
0104     void repopulate();
0105 };