File indexing completed on 2024-04-14 05:19:08

0001 /*
0002  *   SPDX-FileCopyrightText: 2019-2020 Aditya Mehra <aix.m@outlook.com>
0003  *
0004  *   SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #ifndef INSTALLERLISTMODEL_H
0008 #define INSTALLERLISTMODEL_H
0009 
0010 #include <QAbstractListModel>
0011 #include <QJsonArray>
0012 #include "filereader.h"
0013 #include "processcommander.h"
0014 #include "globalconfiguration.h"
0015 
0016 class InstallerListModel : public QAbstractListModel
0017 {
0018     Q_OBJECT
0019     Q_PROPERTY(QString url READ url WRITE setUrl)
0020     Q_PROPERTY(QString json READ json WRITE setJson)
0021     Q_PROPERTY(QString query READ query WRITE setQuery)
0022     Q_PROPERTY(QStringList roles READ roles WRITE setRoles)
0023 
0024 public:
0025     explicit InstallerListModel(QObject *parent = 0);
0026     int rowCount(const QModelIndex &parent) const override;
0027     QHash<int, QByteArray> roleNames() const override;
0028     QVariant data(const QModelIndex &index, int role) const override;
0029 
0030     QString url() const;
0031     void setUrl(const QString &url);
0032     QString json() const;
0033     void setJson(const QString &json);
0034     QString query() const;
0035     void setQuery(const QString &query);
0036     QStringList roles() const;
0037     void setRoles(const QStringList &roles);
0038 
0039     void getSecondaryJson(const QByteArray &data, const QString &url);
0040     void buildJSONModel(const QJsonObject json_one, const QJsonDocument json_two);
0041 
0042     void setReloadModel();
0043 
0044 public Q_SLOTS:
0045     QVariantMap get(int row);
0046     bool checkInstalled(const QString skillname, const QString skillauthor);
0047     bool checkUpdatesAvailable(const QString url, const QString branch, const QString skillpath);
0048     void reloadJsonModel();
0049 
0050     bool downloadingModel();
0051     void setDownloadingModel(bool downloadingModel);
0052 
0053     bool creatingModel();
0054     void setCreatingModel(bool creatingModel);
0055 
0056     int completeModelCounter();
0057     int updatingModelCounter();
0058 
0059     void setCategoryBrowser(int category);
0060     QString getCurrentCategory();
0061 
0062     void fetchLatestForCurrentModel();
0063 
0064 Q_SIGNALS:
0065     void downloadingModelUpdated();
0066     void creatingModelUpdated();
0067     void modelUpdated();
0068 
0069 private:
0070     QString m_url;
0071     QString m_json;
0072     QString m_query;
0073     QStringList m_roles;
0074     QList<QHash<int, QVariant>> m_jsonList;
0075 
0076     QJsonArray m_combinedDoc;
0077     FileReader m_fileReader;
0078     int m_originalCount;
0079     QList<QString> m_blackList;
0080 
0081     bool m_downloadingModel;
0082     bool m_creatingModel;
0083 
0084     bool m_reloadingModel;
0085 
0086     int m_updatingCount;
0087 
0088     QString m_categoryUrl;
0089     QString m_cacheDataPath;
0090     QString m_cacheDataFile;
0091     int m_nonCacheCount;
0092 
0093     GlobalConfiguration *m_globalConfiguration;
0094     QString m_selectedBackendType;
0095     bool m_selectedBackendXdgSupport;
0096 };
0097 
0098 #endif
0099