]> git.mxchange.org Git - flightgear.git/blob - src/GUI/AircraftModel.hxx
Remove some debug noise
[flightgear.git] / src / GUI / AircraftModel.hxx
1 // AircraftModel.hxx - part of GUI launcher using Qt5
2 //
3 // Written by James Turner, started March 2015.
4 //
5 // Copyright (C) 2015 James Turner <zakalawe@mac.com>
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 // General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
21 #ifndef FG_GUI_AIRCRAFT_MODEL
22 #define FG_GUI_AIRCRAFT_MODEL
23
24 #include <QAbstractListModel>
25 #include <QDateTime>
26 #include <QDir>
27 #include <QPixmap>
28 #include <QStringList>
29 #include <QSharedPointer>
30 #include <QUrl>
31
32 #include <simgear/package/Root.hxx>
33
34 const int AircraftPathRole = Qt::UserRole + 1;
35 const int AircraftAuthorsRole = Qt::UserRole + 2;
36 const int AircraftVariantRole = Qt::UserRole + 3;
37 const int AircraftVariantCountRole = Qt::UserRole + 4;
38 const int AircraftThumbnailCountRole = Qt::UserRole + 5;
39 const int AircraftPackageIdRole = Qt::UserRole + 6;
40 const int AircraftPackageStatusRole = Qt::UserRole + 7;
41 const int AircraftPackageProgressRole = Qt::UserRole + 8;
42 const int AircraftLongDescriptionRole = Qt::UserRole + 9;
43 const int AircraftHasRatingsRole = Qt::UserRole + 10;
44 const int AircraftInstallPercentRole = Qt::UserRole + 11;
45 const int AircraftPackageSizeRole = Qt::UserRole + 12;
46 const int AircraftInstallDownloadedSizeRole = Qt::UserRole + 13;
47 const int AircraftURIRole = Qt::UserRole + 14;
48
49 const int AircraftRatingRole = Qt::UserRole + 100;
50 const int AircraftVariantDescriptionRole = Qt::UserRole + 200;
51 const int AircraftThumbnailRole = Qt::UserRole + 300;
52
53 class AircraftScanThread;
54 class QDataStream;
55 class PackageDelegate;
56 struct AircraftItem;
57 typedef QSharedPointer<AircraftItem> AircraftItemPtr;
58
59 struct AircraftItem
60 {
61     AircraftItem();
62
63     AircraftItem(QDir dir, QString filePath);
64     
65     // the file-name without -set.xml suffix
66     QString baseName() const;
67     
68     void fromDataStream(QDataStream& ds);
69
70     void toDataStream(QDataStream& ds) const;
71
72     QPixmap thumbnail() const;
73
74     bool excluded;
75     QString path;
76     QString description;
77     QString authors;
78     int ratings[4];
79     QString variantOf;
80     QDateTime pathModTime;
81
82     QList<AircraftItemPtr> variants;
83 private:
84     mutable QPixmap m_thumbnail;
85 };
86
87
88 enum AircraftItemStatus {
89     PackageNotInstalled = 0,
90     PackageInstalled,
91     PackageUpdateAvailable,
92     PackageQueued,
93     PackageDownloading
94 };
95
96 class AircraftItemModel : public QAbstractListModel
97 {
98     Q_OBJECT
99 public:
100     AircraftItemModel(QObject* pr, simgear::pkg::RootRef& root);
101
102     ~AircraftItemModel();
103
104     void setPaths(QStringList paths);
105
106     void scanDirs();
107
108     virtual int rowCount(const QModelIndex& parent) const;
109     
110     virtual QVariant data(const QModelIndex& index, int role) const;
111     
112     virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
113
114     /**
115      * given a -set.xml path, return the corresponding model index, if one
116      * exists.
117      */
118   //  QModelIndex indexOfAircraftPath(QString path) const;
119
120     QModelIndex indexOfAircraftURI(QUrl uri) const;
121     
122     /**
123      * return if a given aircraft is ready to be run, or not. Aircraft which
124      * are not installed, or are downloading, are not runnable.
125      */
126     bool isIndexRunnable(const QModelIndex& index) const;
127     
128 signals:
129     void aircraftInstallFailed(QModelIndex index, QString errorMessage);
130     
131     void aircraftInstallCompleted(QModelIndex index);
132     
133 private slots:
134     void onScanResults();
135     
136     void onScanFinished();
137
138 private:
139     friend class PackageDelegate;
140
141     QVariant dataFromItem(AircraftItemPtr item, quint32 variantIndex, int role) const;
142
143     QVariant dataFromPackage(const simgear::pkg::PackageRef& item,
144                              quint32 variantIndex, int role) const;
145
146     QVariant packageThumbnail(simgear::pkg::PackageRef p, int index) const;
147     
148     void abandonCurrentScan();
149     void refreshPackages();
150     
151     void installSucceeded(QModelIndex index);
152     void installFailed(QModelIndex index, simgear::pkg::Delegate::StatusCode reason);
153     
154     QStringList m_paths;
155     AircraftScanThread* m_scanThread;
156     QVector<AircraftItemPtr> m_items;
157     PackageDelegate* m_delegate;
158     
159     QVector<quint32> m_activeVariant;
160     QVector<quint32> m_packageVariant;
161     
162     simgear::pkg::RootRef m_packageRoot;
163     simgear::pkg::PackageList m_packages;
164         
165     mutable QHash<QString, QPixmap> m_thumbnailPixmapCache;
166 };
167
168 #endif // of FG_GUI_AIRCRAFT_MODEL