File indexing completed on 2024-12-08 04:58:22

0001 /*
0002     SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef VIEWINDICATOR_H
0007 #define VIEWINDICATOR_H
0008 
0009 // local
0010 #include "indicatorinfo.h"
0011 #include "indicatorresources.h"
0012 
0013 // Qt
0014 #include <QObject>
0015 #include <QPointer>
0016 #include <QQmlComponent>
0017 #include <QQmlContext>
0018 #include <QQuickItem>
0019 
0020 // KDE
0021 #include <KConfigLoader>
0022 #include <KPluginMetaData>
0023 
0024 namespace KDeclarative
0025 {
0026 class ConfigPropertyMap;
0027 class QmlObjectSharedEngine;
0028 }
0029 
0030 namespace Latte {
0031 class Corona;
0032 class View;
0033 }
0034 
0035 namespace Latte {
0036 namespace ViewPart {
0037 
0038 class Indicator: public QObject
0039 {
0040     Q_OBJECT
0041     Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
0042     Q_PROPERTY(bool enabledForApplets READ enabledForApplets WRITE setEnabledForApplets NOTIFY enabledForAppletsChanged)
0043     Q_PROPERTY(bool latteTasksArePresent READ latteTasksArePresent NOTIFY latteTasksArePresentChanged)
0044     Q_PROPERTY(bool pluginIsReady READ pluginIsReady NOTIFY pluginIsReadyChanged)
0045 
0046     Q_PROPERTY(QString type READ type WRITE setType NOTIFY pluginChanged)
0047     Q_PROPERTY(QString customType READ customType NOTIFY customPluginChanged)
0048 
0049     /* Custom plugins */
0050     Q_PROPERTY(int customPluginsCount READ customPluginsCount NOTIFY customPluginsChanged)
0051     Q_PROPERTY(QStringList customPluginIds READ customPluginIds NOTIFY customPluginsChanged)
0052     Q_PROPERTY(QStringList customPluginNames READ customPluginNames NOTIFY customPluginsChanged)
0053     Q_PROPERTY(QStringList customLocalPluginIds READ customLocalPluginIds NOTIFY customPluginsChanged)
0054 
0055     /**
0056      * Configuration object: each config key will be a writable property of this object. property bindings work.
0057      */
0058     Q_PROPERTY(QObject *configuration READ configuration NOTIFY configurationChanged)
0059 
0060     Q_PROPERTY(QQmlComponent *component READ component NOTIFY pluginChanged)
0061     Q_PROPERTY(QQmlComponent *plasmaComponent READ plasmaComponent NOTIFY plasmaComponentChanged)
0062 
0063     /**
0064       * Information provided from the indicator itself
0065       */
0066     Q_PROPERTY(Latte::ViewPart::IndicatorPart::Info *info READ info NOTIFY infoChanged)
0067 
0068     /**
0069       * Resources provided from the indicator itself
0070       */
0071     Q_PROPERTY(Latte::ViewPart::IndicatorPart::Resources *resources READ resources NOTIFY resourcesChanged)
0072 
0073 
0074 public:
0075     Indicator(Latte::View *parent);
0076     virtual ~Indicator();
0077 
0078     bool enabled() const;
0079     void setEnabled(bool enabled);
0080 
0081     bool enabledForApplets() const;
0082     void setEnabledForApplets(bool enabled);
0083 
0084     bool isCustomIndicator() const;
0085 
0086     bool latteTasksArePresent();
0087 
0088     bool pluginIsReady();
0089 
0090     int index(const QString &type);
0091 
0092     QString type() const;
0093     void setType(QString type);
0094 
0095     QString uiPath() const;
0096 
0097     QString customType() const;
0098 
0099     int customPluginsCount() const;
0100     QStringList customPluginIds() const;
0101     QStringList customPluginNames() const;
0102     QStringList customLocalPluginIds() const;
0103 
0104     IndicatorPart::Info *info() const;
0105     IndicatorPart::Resources *resources() const;
0106 
0107     QObject *configuration() const;
0108     QQmlComponent *component() const;
0109     QQmlComponent *plasmaComponent() const;
0110 
0111     void load(QString type);
0112     void unloadIndicators();
0113 
0114 signals:
0115     void customPluginsChanged();
0116     void enabledChanged();
0117     void enabledForAppletsChanged();
0118     void configurationChanged();
0119     void customPluginChanged();
0120     void infoChanged();
0121     void latteTasksArePresentChanged();
0122     void plasmaComponentChanged();
0123     void pluginChanged();
0124     void pluginIsReadyChanged();
0125     void resourcesChanged();
0126 
0127 private:
0128     void loadConfig();
0129     void saveConfig();
0130 
0131     void setPluginIsReady(bool ready);
0132 
0133     void setCustomType(QString type);
0134 
0135     void loadPlasmaComponent();
0136     void updateComponent();
0137     void updateScheme();
0138 
0139 private:
0140     bool m_enabled{true};
0141     bool m_enabledForApplets{true};
0142     bool m_pluginIsReady{false};
0143 
0144     QString m_pluginPath;
0145     QString m_type{"org.kde.latte.default"};
0146     QString m_customType;
0147 
0148     QPointer<QQmlComponent> m_component;
0149     QPointer<QQmlComponent> m_plasmaComponent;
0150     QPointer<QQmlComponent> m_configUi;
0151     QPointer<KConfigLoader> m_configLoader;
0152     QPointer<Latte::Corona> m_corona;
0153     QPointer<Latte::View> m_view;
0154 
0155     KPluginMetaData m_metadata;
0156 
0157     QPointer<IndicatorPart::Info> m_info;
0158     QPointer<IndicatorPart::Resources> m_resources;
0159 
0160     QPointer<KDeclarative::ConfigPropertyMap> m_configuration;
0161 };
0162 
0163 }
0164 }
0165 
0166 #endif