File indexing completed on 2024-04-28 16:49:27
0001 /* 0002 * Copyright 2019 Michail Vourlakos <mvourlakos@gmail.com> 0003 * 0004 * This file is part of Latte-Dock 0005 * 0006 * Latte-Dock is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU General Public License as 0008 * published by the Free Software Foundation; either version 2 of 0009 * the License, or (at your option) any later version. 0010 * 0011 * Latte-Dock is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #ifndef VIEWINDICATOR_H 0021 #define VIEWINDICATOR_H 0022 0023 // local 0024 #include "indicatorinfo.h" 0025 #include "indicatorresources.h" 0026 0027 // Qt 0028 #include <QObject> 0029 #include <QPointer> 0030 #include <QQmlComponent> 0031 #include <QQmlContext> 0032 #include <QQuickItem> 0033 0034 // KDE 0035 #include <KConfigLoader> 0036 #include <KPluginMetaData> 0037 0038 namespace KDeclarative 0039 { 0040 class ConfigPropertyMap; 0041 class QmlObjectSharedEngine; 0042 } 0043 0044 namespace Latte { 0045 class Corona; 0046 class View; 0047 } 0048 0049 namespace Latte { 0050 namespace ViewPart { 0051 0052 class Indicator: public QObject 0053 { 0054 Q_OBJECT 0055 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) 0056 Q_PROPERTY(bool enabledForApplets READ enabledForApplets WRITE setEnabledForApplets NOTIFY enabledForAppletsChanged) 0057 Q_PROPERTY(bool latteTasksArePresent READ latteTasksArePresent NOTIFY latteTasksArePresentChanged) 0058 Q_PROPERTY(bool pluginIsReady READ pluginIsReady NOTIFY pluginIsReadyChanged) 0059 Q_PROPERTY(bool providesConfigUi READ providesConfigUi NOTIFY providesConfigUiChanged) 0060 0061 Q_PROPERTY(float padding READ padding WRITE setPadding NOTIFY paddingChanged) 0062 0063 Q_PROPERTY(QString type READ type WRITE setType NOTIFY pluginChanged) 0064 Q_PROPERTY(QString customType READ customType NOTIFY customPluginChanged) 0065 0066 /* Custom plugins */ 0067 Q_PROPERTY(int customPluginsCount READ customPluginsCount NOTIFY customPluginsChanged) 0068 Q_PROPERTY(QStringList customPluginIds READ customPluginIds NOTIFY customPluginsChanged) 0069 Q_PROPERTY(QStringList customPluginNames READ customPluginNames NOTIFY customPluginsChanged) 0070 Q_PROPERTY(QStringList customLocalPluginIds READ customLocalPluginIds NOTIFY customPluginsChanged) 0071 0072 /** 0073 * Configuration object: each config key will be a writable property of this object. property bindings work. 0074 */ 0075 Q_PROPERTY(QObject *configuration READ configuration NOTIFY pluginChanged) 0076 0077 Q_PROPERTY(QQmlComponent *component READ component NOTIFY pluginChanged) 0078 Q_PROPERTY(QQmlComponent *plasmaComponent READ plasmaComponent NOTIFY plasmaComponentChanged) 0079 0080 /** 0081 * Information provided from the indicator itself 0082 */ 0083 Q_PROPERTY(Latte::ViewPart::IndicatorPart::Info *info READ info NOTIFY infoChanged) 0084 0085 /** 0086 * Resources provided from the indicator itself 0087 */ 0088 Q_PROPERTY(Latte::ViewPart::IndicatorPart::Resources *resources READ resources NOTIFY resourcesChanged) 0089 0090 0091 public: 0092 Indicator(Latte::View *parent); 0093 virtual ~Indicator(); 0094 0095 bool enabled() const; 0096 void setEnabled(bool enabled); 0097 0098 bool enabledForApplets() const; 0099 void setEnabledForApplets(bool enabled); 0100 0101 bool latteTasksArePresent(); 0102 bool providesConfigUi() const; 0103 0104 bool pluginIsReady(); 0105 0106 float padding() const; 0107 void setPadding(float padding); 0108 0109 QString type() const; 0110 void setType(QString type); 0111 0112 QString uiPath() const; 0113 0114 QString customType() const; 0115 0116 int customPluginsCount() const; 0117 QStringList customPluginIds() const; 0118 QStringList customPluginNames() const; 0119 QStringList customLocalPluginIds() const; 0120 0121 IndicatorPart::Info *info() const; 0122 IndicatorPart::Resources *resources() const; 0123 0124 QObject *configuration() const; 0125 QQmlComponent *component() const; 0126 QQmlComponent *plasmaComponent() const; 0127 0128 void load(QString type); 0129 void unloadIndicators(); 0130 0131 public slots: 0132 Q_INVOKABLE void configUiFor(QString type, QQuickItem *parent); 0133 Q_INVOKABLE void addIndicator(); 0134 Q_INVOKABLE void downloadIndicator(); 0135 Q_INVOKABLE void removeIndicator(QString pluginId); 0136 0137 signals: 0138 void customPluginsChanged(); 0139 void enabledChanged(); 0140 void enabledForAppletsChanged(); 0141 void customPluginChanged(); 0142 void infoChanged(); 0143 void latteTasksArePresentChanged(); 0144 void paddingChanged(); 0145 void plasmaComponentChanged(); 0146 void pluginChanged(); 0147 void pluginIsReadyChanged(); 0148 void providesConfigUiChanged(); 0149 void resourcesChanged(); 0150 0151 private: 0152 void loadConfig(); 0153 void saveConfig(); 0154 0155 void setPluginIsReady(bool ready); 0156 void setProvidesConfigUi(bool provides); 0157 0158 void setCustomType(QString type); 0159 0160 void loadPlasmaComponent(); 0161 void updateComponent(); 0162 void updateScheme(); 0163 0164 private: 0165 bool m_enabled{true}; 0166 bool m_enabledForApplets{true}; 0167 bool m_pluginIsReady{false}; 0168 bool m_providesConfigUi{true}; 0169 0170 float m_padding{0.08}; 0171 0172 QString m_pluginPath; 0173 QString m_type{"org.kde.latte.default"}; 0174 QString m_customType; 0175 0176 QPointer<QQmlComponent> m_component; 0177 QPointer<QQmlComponent> m_plasmaComponent; 0178 QPointer<QQmlComponent> m_configUi; 0179 QPointer<KConfigLoader> m_configLoader; 0180 QPointer<Latte::Corona> m_corona; 0181 QPointer<Latte::View> m_view; 0182 0183 KPluginMetaData m_metadata; 0184 0185 QPointer<IndicatorPart::Info> m_info; 0186 QPointer<IndicatorPart::Resources> m_resources; 0187 0188 QPointer<KDeclarative::ConfigPropertyMap> m_configuration; 0189 QPointer<KDeclarative::QmlObjectSharedEngine> m_lastCreatedConfigUi; 0190 }; 0191 0192 } 0193 } 0194 0195 #endif