]> git.mxchange.org Git - flightgear.git/blob - src/GUI/AircraftModel.hxx
AircraftModel hacking for package support.
[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
30 #include <simgear/package/Root.hxx>
31
32 const int AircraftPathRole = Qt::UserRole + 1;
33 const int AircraftAuthorsRole = Qt::UserRole + 2;
34 const int AircraftVariantRole = Qt::UserRole + 3;
35 const int AircraftVariantCountRole = Qt::UserRole + 4;
36 const int AircraftThumbnailCountRole = Qt::UserRole + 5;
37 const int AircraftPackageIdRole = Qt::UserRole + 6;
38 const int AircraftPackageStatusRole = Qt::UserRole + 7;
39 const int AircraftPackageProgressRole = Qt::UserRole + 8;
40
41 const int AircraftRatingRole = Qt::UserRole + 100;
42 const int AircraftVariantDescriptionRole = Qt::UserRole + 200;
43 const int AircraftThumbnailRole = Qt::UserRole + 300;
44
45 class AircraftScanThread;
46 class QDataStream;
47
48 struct AircraftItem
49 {
50     AircraftItem();
51
52     AircraftItem(QDir dir, QString filePath);
53     
54     // the file-name without -set.xml suffix
55     QString baseName() const;
56     
57     void fromDataStream(QDataStream& ds);
58
59     void toDataStream(QDataStream& ds) const;
60
61     QPixmap thumbnail() const;
62
63     QString path;
64     QString description;
65     QString authors;
66     int ratings[4];
67     QString variantOf;
68     QDateTime pathModTime;
69
70     QList<AircraftItem*> variants;
71 private:
72     mutable QPixmap m_thumbnail;
73 };
74
75 class AircraftItemModel : public QAbstractListModel
76 {
77     Q_OBJECT
78 public:
79     AircraftItemModel(QObject* pr, simgear::pkg::RootRef& root);
80
81     ~AircraftItemModel();
82
83     void setPaths(QStringList paths);
84
85     void scanDirs();
86
87     virtual int rowCount(const QModelIndex& parent) const
88     {
89         return m_items.size();
90     }
91
92     virtual QVariant data(const QModelIndex& index, int role) const;
93     
94     virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
95
96     /**
97      * given a -set.xml path, return the corresponding model index, if one
98      * exists.
99      */
100     QModelIndex indexOfAircraftPath(QString path) const;
101
102     enum {
103         PackageNotInstalled,
104         PackageInstalled,
105         PackageUpdateAvailable,
106         PackageDownloading
107     };
108 private slots:
109     void onScanResults();
110     
111     void onScanFinished();
112
113 private:
114     QVariant dataFromItem(const AircraftItem* item, quint32 variantIndex, int role) const;
115
116     QVariant dataFromPackage(const simgear::pkg::PackageRef& item,
117                              quint32 variantIndex, int role) const;
118
119     void abandonCurrentScan();
120
121     QStringList m_paths;
122     AircraftScanThread* m_scanThread;
123     QList<AircraftItem*> m_items;
124     QList<quint32> m_activeVariant;
125     simgear::pkg::RootRef m_packageRoot;
126 };
127
128 #endif // of FG_GUI_AIRCRAFT_MODEL