File indexing completed on 2024-11-24 05:01:59

0001 /*
0002     SPDX-FileCopyrightText: 2007 Ivan Cukic <ivan.cukic+kde@gmail.com>
0003     SPDX-FileCopyrightText: 2009 Ana Cecília Martins <anaceciliamb@gmail.com>
0004     SPDX-FileCopyrightText: 2013 Sebastian Kügler <sebas@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #pragma once
0010 
0011 #include <QAction>
0012 #include <QObject>
0013 #include <QQmlParserStatus>
0014 
0015 #include <Plasma/Plasma>
0016 
0017 #include "plasmaappletitemmodel_p.h"
0018 
0019 namespace Plasma
0020 {
0021 class Corona;
0022 class Containment;
0023 class Applet;
0024 }
0025 class WidgetExplorerPrivate;
0026 
0027 // We need to access the separator property that is not exported by QAction
0028 class WidgetAction : public QAction
0029 {
0030     Q_OBJECT
0031     Q_PROPERTY(bool separator READ isSeparator WRITE setSeparator NOTIFY separatorChanged)
0032 
0033 public:
0034     explicit WidgetAction(QObject *parent = nullptr);
0035     WidgetAction(const QIcon &icon, const QString &text, QObject *parent);
0036 
0037 Q_SIGNALS:
0038     void separatorChanged();
0039 };
0040 
0041 class WidgetExplorer : public QObject, public QQmlParserStatus
0042 {
0043     Q_OBJECT
0044     Q_INTERFACES(QQmlParserStatus)
0045 
0046     /**
0047      * Model that lists all applets
0048      */
0049     Q_PROPERTY(QObject *widgetsModel READ widgetsModel CONSTANT)
0050 
0051     /**
0052      * Model that lists all applets filters and categories
0053      */
0054     Q_PROPERTY(QObject *filterModel READ filterModel CONSTANT)
0055 
0056     /**
0057      * Whether to show special filters such as "Running" and "Uninstallable" in the filterModel.
0058      */
0059     Q_PROPERTY(bool showSpecialFilters READ showSpecialFilters WRITE setShowSpecialFilters NOTIFY showSpecialFiltersChanged)
0060 
0061     /**
0062      * Actions for adding widgets, like download plasma widgets, download google gadgets, install from local file
0063      */
0064     Q_PROPERTY(QList<QObject *> widgetsMenuActions READ widgetsMenuActions NOTIFY widgetsMenuActionsChanged)
0065 
0066     /**
0067      * The application that owns the widget list. different application may show different lists
0068      */
0069     Q_PROPERTY(QString application READ application WRITE setApplication NOTIFY applicationChanged)
0070 
0071     /**
0072      * Set the features the listed applets must provide: needed for listing alternatives
0073      * to a particular applet
0074      */
0075     Q_PROPERTY(QStringList provides READ provides WRITE setProvides NOTIFY providesChanged)
0076 
0077     Q_PROPERTY(Plasma::Containment *containment READ containment WRITE setContainment NOTIFY containmentChanged)
0078 
0079 public:
0080     explicit WidgetExplorer(QObject *parent = nullptr);
0081     ~WidgetExplorer() override;
0082 
0083     QString application();
0084 
0085     /**
0086      * Populates the widget list for the given application. This must be called
0087      * before the widget explorer will be usable as the widget list will remain
0088      * empty up to that point.
0089      *
0090      * @arg application the application which the widgets should be loaded for.
0091      */
0092     void setApplication(const QString &application = QString());
0093 
0094     QStringList provides() const;
0095     void setProvides(const QStringList &provides);
0096 
0097     /**
0098      * Changes the current default containment to add applets to
0099      *
0100      * @arg containment the new default
0101      */
0102     void setContainment(Plasma::Containment *containment);
0103 
0104     /**
0105      * @return the current default containment to add applets to
0106      */
0107     Plasma::Containment *containment() const;
0108     /**
0109      * @return the current corona this widget is added to
0110      */
0111     Plasma::Corona *corona() const;
0112 
0113     QObject *widgetsModel() const;
0114     QObject *filterModel() const;
0115 
0116     bool showSpecialFilters() const;
0117     void setShowSpecialFilters(bool show);
0118 
0119     QList<QObject *> widgetsMenuActions();
0120 
0121     /**
0122      * Uninstall a plasmoid with a given plugin name. only user-installed ones are uninstallable
0123      */
0124     Q_INVOKABLE void uninstall(const QString &pluginName);
0125 
0126     void classBegin() override;
0127     void componentComplete() override;
0128 
0129 Q_SIGNALS:
0130     void widgetsMenuActionsChanged();
0131     void extraActionsChanged();
0132     void shouldClose();
0133     void viewChanged();
0134     void applicationChanged();
0135     void containmentChanged();
0136     void providesChanged();
0137 
0138 public Q_SLOTS:
0139     /**
0140      * Adds currently selected applets
0141      */
0142     void addApplet(const QString &pluginName);
0143     void openWidgetFile();
0144     void downloadWidgets();
0145 
0146 Q_SIGNALS:
0147     void showSpecialFiltersChanged() const;
0148 
0149 protected Q_SLOTS:
0150     void immutabilityChanged(Plasma::Types::ImmutabilityType);
0151 
0152 private:
0153     Q_PRIVATE_SLOT(d, void appletAdded(Plasma::Applet *))
0154     Q_PRIVATE_SLOT(d, void appletRemoved(Plasma::Applet *))
0155     Q_PRIVATE_SLOT(d, void containmentDestroyed())
0156 
0157     WidgetExplorerPrivate *const d;
0158     friend class WidgetExplorerPrivate;
0159 };