1 /*
2     SPDX-FileCopyrightText: 2013 Marco Martin <mart@kde.org>
3 
4     SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #ifndef WALLPAPERINTERFACE_H
8 #define WALLPAPERINTERFACE_H
9 
10 #include <QQmlEngine>
11 #include <QQuickItem>
12 
13 #include <KPackage/Package>
14 
15 class KConfigLoader;
16 class KActionCollection;
17 
18 class ContainmentInterface;
19 
20 namespace KDeclarative
21 {
22 class ConfigPropertyMap;
23 class QmlObject;
24 }
25 
26 /**
27  * @class WallpaperInterface
28  *
29  * @brief This class is exposed to wallpapers as the attached property "wallpaper"
30  *
31  *
32  */
33 class WallpaperInterface : public QQuickItem
34 {
35     Q_OBJECT
36 
37     Q_PROPERTY(QString pluginName READ pluginName NOTIFY packageChanged)
38     Q_PROPERTY(KDeclarative::ConfigPropertyMap *configuration READ configuration NOTIFY configurationChanged)
39     Q_PROPERTY(bool loading MEMBER m_loading NOTIFY isLoadingChanged)
40 
41 public:
42     explicit WallpaperInterface(ContainmentInterface *parent = nullptr);
43     ~WallpaperInterface() override;
44 
45     /**
46      * Returns a list of all known wallpapers that can accept the given mimetype
47      * @param mimetype the mimetype to search for
48      * @param formFactor the format of the wallpaper being search for (e.g. desktop)
49      * @return list of wallpapers
50      */
51     static QList<KPluginMetaData> listWallpaperMetadataForMimetype(const QString &mimetype, const QString &formFactor = QString());
52 
53     KPackage::Package kPackage() const;
54 
55     QString pluginName() const;
56 
57     KDeclarative::ConfigPropertyMap *configuration() const;
58 
59     KConfigLoader *configScheme();
60 
61     QList<QAction *> contextualActions() const;
62 
63     bool supportsMimetype(const QString &mimetype) const;
64 
65     void setUrl(const QUrl &urls);
66 
67     Q_INVOKABLE void setAction(const QString &name, const QString &text, const QString &icon = QString(), const QString &shortcut = QString());
68 
69     Q_INVOKABLE void removeAction(const QString &name);
70 
71     Q_INVOKABLE QAction *action(QString name) const;
72 
73     static WallpaperInterface *qmlAttachedProperties(QObject *object);
74 
75     bool isLoading() const;
76 
77 Q_SIGNALS:
78     void packageChanged();
79     void configurationChanged();
80     void isLoadingChanged();
81 
82 private Q_SLOTS:
83     void syncWallpaperPackage();
84     void executeAction(const QString &name);
85     void loadFinished();
86 
87 private:
88     QString m_wallpaperPlugin;
89     ContainmentInterface *m_containmentInterface;
90     KDeclarative::QmlObject *m_qmlObject;
91     KPackage::Package m_pkg;
92     KDeclarative::ConfigPropertyMap *m_configuration;
93     KConfigLoader *m_configLoader;
94     KActionCollection *m_actions;
95     bool m_loading = false;
96 
97     static QHash<QObject *, WallpaperInterface *> s_rootObjects;
98 };
99 
100 QML_DECLARE_TYPEINFO(WallpaperInterface, QML_HAS_ATTACHED_PROPERTIES)
101 
102 #endif
103