File indexing completed on 2024-10-13 10:49:18

0001 /*
0002     SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef INDICATORFACTORY_H
0007 #define INDICATORFACTORY_H
0008 
0009 // local
0010 #include "../apptypes.h"
0011 
0012 // Qt
0013 #include <QHash>
0014 #include <QObject>
0015 #include <QWidget>
0016 
0017 class KPluginMetaData;
0018 
0019 namespace Latte {
0020 namespace Indicator {
0021 
0022 class Factory : public QObject
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     Factory(QObject *parent);
0028     ~Factory() override;
0029 
0030     int customPluginsCount();
0031     QStringList customPluginIds();
0032     QStringList customPluginNames();
0033     QStringList customLocalPluginIds();
0034 
0035     KPluginMetaData metadata(QString pluginId);
0036 
0037     void downloadIndicator();
0038     void removeIndicator(QString id);
0039 
0040     bool pluginExists(QString id) const;
0041     bool isCustomType(const QString &id) const;
0042 
0043     QString uiPath(QString pluginName) const;
0044 
0045     static QString metadataFileAbsolutePath(const QString &directoryPath);
0046 
0047     //! metadata record
0048     static bool metadataAreValid(KPluginMetaData &metadata);
0049     //! metadata file
0050     static bool metadataAreValid(QString &file);
0051 
0052     //! imports an indicator compressed file
0053     static Latte::ImportExport::State importIndicatorFile(QString compressedFile);
0054 signals:
0055     void indicatorChanged(const QString &indicatorId);
0056     void indicatorRemoved(const QString &indicatorId);
0057 
0058 private:
0059     void reload(const QString &indicatorPath);
0060 
0061     void removeIndicatorRecords(const QString &path);
0062     void discoverNewIndicators(const QString &main);
0063 
0064 private:
0065     QHash<QString, KPluginMetaData> m_plugins;
0066     QHash<QString, QString> m_pluginUiPaths;
0067 
0068     QStringList m_customPluginIds;
0069     QStringList m_customPluginNames;
0070     QStringList m_customLocalPluginIds;
0071 
0072     //! plugins paths
0073     QStringList m_mainPaths;
0074     QStringList m_indicatorsPaths;
0075 
0076     QWidget *m_parentWidget;
0077 };
0078 
0079 }
0080 }
0081 
0082 #endif