2015-03-12 13:29:06 +00:00
|
|
|
// CatalogListModel.hxx - part of GUI launcher using Qt5
|
|
|
|
//
|
|
|
|
// Written by James Turner, started March 2015.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2015 James Turner <zakalawe@mac.com>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
#ifndef FG_GUI_CATALOG_LIST_MODEL
|
|
|
|
#define FG_GUI_CATALOG_LIST_MODEL
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QStringList>
|
2020-06-01 18:00:28 +00:00
|
|
|
#include <QUrl>
|
2015-03-12 13:29:06 +00:00
|
|
|
|
|
|
|
#include <simgear/package/Root.hxx>
|
|
|
|
#include <simgear/package/Catalog.hxx>
|
|
|
|
|
|
|
|
const int CatalogUrlRole = Qt::UserRole + 1;
|
|
|
|
const int CatalogIdRole = Qt::UserRole + 2;
|
2015-03-12 22:43:58 +00:00
|
|
|
const int CatalogPackageCountRole = Qt::UserRole + 3;
|
|
|
|
const int CatalogInstallCountRole = Qt::UserRole + 4;
|
2018-03-16 22:01:21 +00:00
|
|
|
const int CatalogStatusRole = Qt::UserRole + 5;
|
|
|
|
const int CatalogDescriptionRole = Qt::UserRole + 6;
|
|
|
|
const int CatalogNameRole = Qt::UserRole + 7;
|
|
|
|
const int CatalogIsNewlyAdded = Qt::UserRole + 8;
|
2020-02-24 11:32:43 +00:00
|
|
|
const int CatalogEnabled = Qt::UserRole + 9;
|
2018-03-16 22:01:21 +00:00
|
|
|
|
|
|
|
class CatalogDelegate;
|
2015-03-12 13:29:06 +00:00
|
|
|
|
|
|
|
class CatalogListModel : public QAbstractListModel
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2018-03-16 22:01:21 +00:00
|
|
|
|
|
|
|
Q_PROPERTY(bool isAddingCatalog READ isAddingCatalog NOTIFY isAddingCatalogChanged)
|
|
|
|
Q_PROPERTY(CatalogStatus statusOfAddingCatalog READ statusOfAddingCatalog NOTIFY statusOfAddingCatalogChanged)
|
2015-03-12 13:29:06 +00:00
|
|
|
public:
|
2018-03-16 22:01:21 +00:00
|
|
|
CatalogListModel(QObject* pr, const simgear::pkg::RootRef& root);
|
2015-03-12 13:29:06 +00:00
|
|
|
|
|
|
|
~CatalogListModel();
|
|
|
|
|
2018-02-28 17:56:40 +00:00
|
|
|
int rowCount(const QModelIndex& parent) const override;
|
2015-03-12 13:29:06 +00:00
|
|
|
|
2018-02-28 17:56:40 +00:00
|
|
|
QVariant data(const QModelIndex& index, int role) const override;
|
2015-03-12 13:29:06 +00:00
|
|
|
|
2018-02-28 17:56:40 +00:00
|
|
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
|
|
|
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
2015-03-12 13:29:06 +00:00
|
|
|
|
2018-03-16 22:01:21 +00:00
|
|
|
QHash<int, QByteArray> roleNames() const override;
|
|
|
|
|
|
|
|
Q_INVOKABLE void removeCatalog(int index);
|
|
|
|
|
|
|
|
Q_INVOKABLE void refreshCatalog(int index);
|
|
|
|
|
|
|
|
Q_INVOKABLE void installDefaultCatalog();
|
|
|
|
|
|
|
|
// returns the index of the new catalog
|
|
|
|
Q_INVOKABLE void addCatalogByUrl(QUrl url);
|
|
|
|
|
|
|
|
Q_INVOKABLE void finalizeAddCatalog();
|
|
|
|
|
|
|
|
Q_INVOKABLE void abandonAddCatalog();
|
|
|
|
|
|
|
|
bool isAddingCatalog() const;
|
|
|
|
|
|
|
|
enum CatalogStatus
|
|
|
|
{
|
|
|
|
Ok = 0,
|
|
|
|
Refreshing,
|
|
|
|
NetworkError,
|
|
|
|
NotFoundOnServer,
|
|
|
|
IncomaptbleVersion,
|
|
|
|
HTTPForbidden,
|
|
|
|
InvalidData,
|
|
|
|
UnknownError,
|
|
|
|
NoAddInProgress
|
|
|
|
};
|
2015-03-12 13:29:06 +00:00
|
|
|
|
2018-05-08 21:17:07 +00:00
|
|
|
Q_ENUMS(CatalogStatus)
|
2018-03-16 22:01:21 +00:00
|
|
|
|
|
|
|
void onCatalogStatusChanged(simgear::pkg::Catalog *cat);
|
|
|
|
|
|
|
|
CatalogStatus statusOfAddingCatalog() const;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void isAddingCatalogChanged();
|
|
|
|
void statusOfAddingCatalogChanged();
|
|
|
|
|
|
|
|
void catalogsChanged();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void resetData();
|
|
|
|
|
|
|
|
private slots:
|
2015-03-12 13:29:06 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
simgear::pkg::RootRef m_packageRoot;
|
2018-02-28 17:56:40 +00:00
|
|
|
simgear::pkg::CatalogList m_catalogs;
|
2018-03-16 22:01:21 +00:00
|
|
|
|
|
|
|
simgear::pkg::CatalogRef m_newlyAddedCatalog;
|
|
|
|
|
|
|
|
int indexOf(QUrl url);
|
|
|
|
|
|
|
|
CatalogDelegate* m_delegate;
|
|
|
|
|
|
|
|
CatalogStatus translateStatusForCatalog(simgear::pkg::CatalogRef cat) const;
|
2015-03-12 13:29:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // of FG_GUI_CATALOG_LIST_MODEL
|