File indexing completed on 2024-04-14 03:47:58
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2012 Dennis Nienhüser <nienhueser@kde.org> 0004 // 0005 0006 #ifndef MARBLE_NEWSTUFFMODEL_H 0007 #define MARBLE_NEWSTUFFMODEL_H 0008 0009 #include "marble_export.h" 0010 0011 #include <QAbstractListModel> 0012 0013 class QNetworkReply; 0014 0015 namespace Marble 0016 { 0017 0018 class NewstuffModelPrivate; 0019 0020 class MARBLE_EXPORT NewstuffModel : public QAbstractListModel 0021 { 0022 Q_OBJECT 0023 0024 Q_PROPERTY(int count READ count NOTIFY countChanged) 0025 Q_PROPERTY(QString provider READ provider WRITE setProvider NOTIFY providerChanged) 0026 Q_PROPERTY(QString targetDirectory READ targetDirectory WRITE setTargetDirectory NOTIFY targetDirectoryChanged) 0027 Q_PROPERTY(QString registryFile READ registryFile WRITE setRegistryFile NOTIFY registryFileChanged) 0028 0029 public: 0030 enum NewstuffRoles { 0031 Name = Qt::UserRole + 1, 0032 Author, 0033 License, 0034 Summary, 0035 Version, 0036 ReleaseDate, 0037 Preview, 0038 Payload, 0039 InstalledVersion, 0040 InstalledReleaseDate, 0041 InstalledFiles, 0042 IsInstalled, 0043 IsUpgradable, 0044 Category, 0045 IsTransitioning, 0046 PayloadSize, 0047 DownloadedSize 0048 }; 0049 0050 enum IdTag { 0051 PayloadTag, 0052 NameTag 0053 }; 0054 0055 /** Constructor */ 0056 explicit NewstuffModel( QObject *parent = nullptr ); 0057 0058 /** Destructor */ 0059 ~NewstuffModel() override; 0060 0061 /** Overload of QAbstractListModel */ 0062 int rowCount ( const QModelIndex &parent = QModelIndex() ) const override; 0063 0064 /** Overload of QAbstractListModel */ 0065 QVariant data ( const QModelIndex &index, int role = Qt::DisplayRole ) const override; 0066 0067 /** Overload of QAbstractListModel */ 0068 QHash<int, QByteArray> roleNames() const override; 0069 0070 /** @todo FIXME https://bugreports.qt-project.org/browse/QTCOMPONENTS-1206 */ 0071 int count() const; 0072 0073 /** 0074 * Add a newstuff provider 0075 */ 0076 void setProvider( const QString &downloadUrl ); 0077 0078 QString provider() const; 0079 0080 void setTargetDirectory( const QString &targetDirectory ); 0081 0082 QString targetDirectory() const; 0083 0084 void setRegistryFile( const QString ®istryFile, IdTag idTag = PayloadTag ); 0085 0086 QString registryFile() const; 0087 0088 public Q_SLOTS: 0089 void install( int index ); 0090 0091 void uninstall( int index ); 0092 0093 void cancel( int index ); 0094 0095 Q_SIGNALS: 0096 void countChanged(); 0097 0098 void providerChanged(); 0099 0100 void targetDirectoryChanged(); 0101 0102 void registryFileChanged(); 0103 0104 void installationProgressed( int newstuffindex, qreal progress ); 0105 0106 void installationFinished( int newstuffindex ); 0107 0108 void installationFailed( int newstuffindex, const QString &error ); 0109 0110 void uninstallationFinished( int newstuffindex ); 0111 0112 private Q_SLOTS: 0113 void updateProgress( qint64 bytesReceived, qint64 bytesTotal ); 0114 0115 void retrieveData(); 0116 0117 void mapInstalled( int exitStatus ); 0118 0119 void mapUninstalled(); 0120 0121 void contentsListed( int exitStatus ); 0122 0123 private: 0124 NewstuffModelPrivate* const d; 0125 friend class NewstuffModelPrivate; 0126 0127 Q_PRIVATE_SLOT( d, void handleProviderData( QNetworkReply* ) ) 0128 }; 0129 0130 } 0131 0132 #endif // MARBLE_NEWSTUFFMODEL_H